File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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 Make it so: Java DB Connections & Transactions this week in the JDBC 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
It's not a secret anymore!