#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2001
    Location
    chennai,india
    Posts
    0
    Rep Power
    0
    how to find out the differnece in days between two dates
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2001
    Posts
    68
    Rep Power
    14
    Are you using a database???
  4. #3
  5. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2001
    Location
    the big smoke - London !
    Posts
    0
    Rep Power
    0
    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...
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2001
    Posts
    68
    Rep Power
    14
    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...

IMN logo majestic logo threadwatch logo seochat tools logo