
April 30th, 2001, 11:45 AM
|
|
Junior Member
|
|
Join Date: Apr 2001
Location: the big smoke - London !
Posts: 0
Time spent in forums: < 1 sec
Reputation Power: 0
|
|
Quote: Originally posted by kollarao
how to find out the differnece in days between two dates |
Difference between 2 dates in Java ?
Well - that all depends, but the basic theory I guess is that if you have 2 java.util.Date objects, date1 and date 2, then
long dif = (date1.getTime() - date2.getTime()) / (1000*60*60*24);
which get the difference in milliseconds between the two date objects, and then multiplies it by 1000 (to put it into second), 60 (into minutes), 60 (into hours) and 24 (into days).
And of course this will work for java.sql.Date objects (if you are getting dates out of databases), as they subclass the java.util.Date object.
<disclaimer> I havn't tried the above code - but I think that should all work ! Might need to cast int's or long's somwhere...
|