File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Java in General and the fly likes Comparing 2 dates Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Comparing 2 dates " Watch "Comparing 2 dates " New topic

Comparing 2 dates

Preeti Sikri
Ranch Hand

Joined: Mar 01, 2001
Posts: 30
I have a field called Last updated date and I alread have some date in that field Now what I want to do is compare last updated with current date and see if the last update date is from within last 5 month and then I want to print new. Please help me my pseduo code is something like this
If (last-updated-date lasser then last 5 months)
Any help would be great.
paul wheaton

Joined: Dec 14, 1998
Posts: 20966

It seems to me that the date stuff in java has been iffy in the past. A few years ago I mashed my C++ date stuff into Java and have been using that ever since. There might be some new stuff in the java libraries that will do what you want, but I'm not familiar with it.
If you like, I've made my libraries free. See and look for the JDate and GDate stuff. Just convert your dates to JDate and these have comparators. Or, you could extract the int values and compare them.

permaculture Wood Burning Stoves 2.0 - 4-DVD set
Rob Ross

Joined: Jan 07, 2002
Posts: 2205
The Calendar class works like a champ for what you need. Here's a little sample program:

Hope this helps!
[ January 08, 2002: Message edited by: Rob Ross ]

SCJP 1.4
I agree. Here's the link:
subject: Comparing 2 dates
It's not a secret anymore!