I need to find the difference between days ? How many days?
Main Topics
Browse All TopicsHow do I get the difference (int value) of two java.util.Date dates?
Like difference between 2007-05-31 and 2007-05-29 is 2.
Thanks.
_Esam
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
Yeah I figured you could continue the logic on your own but here it is for you
Date start=....;
Date end=....;
long diffInMilleseconds = end.getTime() - start.getTime();
long diffInSeconds = diffInMilleseconds/1000;
long diffInMinutes = diffInSeconds/60;
long diffInHours = diffInMinutes/60;
long diffInDays = diffInHours/24;
Yep - you can. THe easiest way is getting the difference in milliseconds and making the days in the same way as above + some casting to int for example.
See this: http://www.exampledepot.co
Another way (IF both dates are in the same year - otherwise it becomes a bit complicated but still achievable) is to check which day is every date in the year http://java.sun.com/j2se/1
This is also a good article on dates and calculations with them in Java: http://www.javaworld.com/j
The accepted solution has problems and will yield incorrect results in countries that have Day light savings (US, UK, Europe etc)
You can check out the solution given here for the correct way of doing this:
http://tripoverit.blogspot
Business Accounts
Answer for Membership
by: NHBFighterPosted on 2007-05-31 at 10:10:24ID: 19189862
Date start=....;
Date end=....;
long diffInMilleseconds = end.getTime() - start.getTime();
long diffInSeconds = diffInMilleseconds/1000;
long diffInMinutes = diffInSeconds/60;