File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes Compare 2 java.util.Dates Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Compare 2 java.util.Dates" Watch "Compare 2 java.util.Dates" New topic
Author

Compare 2 java.util.Dates

Kip Dekan
Greenhorn

Joined: Apr 22, 2003
Posts: 9
Hi,
I've got a simple problem please help me,
I have 2 java.util.Date() Objects
e.g.
date1 = 2003 Jul 01 12:45:36
date2 = 2003 Jul 01 09:08:59
now I'd like to compare the two dates without the Time Part
that means:
if(date1.compareTo(date2) = 0) should return 0
now the question how to compare only the DatePart of a java.util.Date?
Thanks for helping
[ July 03, 2003: Message edited by: Dekan ]
Susilo Saja
Ranch Hand

Joined: May 27, 2003
Posts: 91
Hi Dekan,
You can get the year, month, and date with getYear(), getMonth(), and getDate() from both Date object, then compare it. But since it's deprecated, you can use class GregorianCalendar instead. There is the method get(int field).
Susilo
Kip Dekan
Greenhorn

Joined: Apr 22, 2003
Posts: 9
Thanks
now it works
Dirk Schreckmann
Sheriff

Joined: Dec 10, 2001
Posts: 7023
Dekan,
Welcome to JavaRanch!
We ain't got many rules 'round these parts, but we do got one. Please change your display name to comply with The JavaRanch Naming Policy.
Thanks Pardner! Hope to see you 'round the Ranch!


[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
 
 
subject: Compare 2 java.util.Dates
 
Similar Threads
How to compare 2 Dates in String Format
How to Compare two Calendar Objects.
How do i convert a Date object into a TimeStamp object
How to get past date ?
Calculate Number of Days Between Two Days