• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Comparing 2 dates

 
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi
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)
{
print("new");
}
else{
print("old");
}
Any help would be great.
Thanks
 
Trailboss
Posts: 23773
IntelliJ IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 www.javaranch.com/common.jsp 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.
 
Bartender
Posts: 2205
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The Calendar class works like a champ for what you need. Here's a little sample program:

Hope this helps!
Rob
[ January 08, 2002: Message edited by: Rob Ross ]
 
I'd appreciate it if you pronounced my name correctly. Pinhead, with a silent "H". Petite ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic