This week's book giveaway is in the OCMJEA forum.
We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Subtracting Dates in JAVA Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Subtracting Dates in JAVA" Watch "Subtracting Dates in JAVA" New topic

Subtracting Dates in JAVA

Sam Drake
Ranch Hand

Joined: Jun 05, 2003
Posts: 33
Can anybody give me a code snippet to subtract dates in JAVA? The idea is to get the number of days between any 2 dates.
Manfred Leonhardt
Ranch Hand

Joined: Jan 09, 2001
Posts: 1492
How about getting the difference in milliseconds:
d1.getTime() - d2.getTime();
Jason Menard

Joined: Nov 09, 2000
Posts: 6450
Check out this thread.
I agree. Here's the link:
subject: Subtracting Dates in JAVA