Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
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


Win a copy of Soft Skills this week in the Jobs Discussion forum!
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: 169
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: 19783
    
  20

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: 169
Wrong code:
please provide inputs "04/06/2008" and "05/09/2008".
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19783
    
  20

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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Calculating Days