Meaningless Drivel is fun!*
The moose likes Other JSE/JEE APIs and the fly likes Calculating Days Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Other JSE/JEE APIs
Bookmark "Calculating Days" Watch "Calculating Days" New topic
Author

Calculating Days

francis varkey
Ranch Hand

Joined: Sep 13, 2005
Posts: 166
Respected Sirs,

What is the best way for calculating number of days between two dates(java.util.Date object) ?

Thanks
Francis
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19656
    
  18

Use java.util.Calendar:


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
francis varkey
Ranch Hand

Joined: Sep 13, 2005
Posts: 166
Wrong code:
please provide inputs "04/06/2008" and "05/09/2008".
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19656
    
  18

Which produces 93, just like Visual Basic's DateDiff function does.
Well, that, is, using dd/MM/yyyy as the format. Otherwise it's 33, just like Visual Basic's DateDiff function does
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Calculating Days
 
Similar Threads
program calculating the mode
Invoking abstract method
caculating the difference between dates
Date arithmetic
Date and Time manipulation