April 23rd, 2001, 02:26 AM
how to find out the differnece in days between two dates
April 24th, 2001, 03:27 PM
Are you using a database???
April 30th, 2001, 11:45 AM
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...
April 30th, 2001, 11:59 AM
Well, if you are getting it out of a database, sql supplies you with functions for it.
You can determine days between, seconds... months.. how many days til next friday... etc...
I was unsure on how to it JAVA-wise...