• 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

I want to compare 4 date values...

 
Ranch Hand
Posts: 69
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i have to compare 4 date values & find the greatest date in it..
plz reply me immediately if possible with some example code.
thanks in advance
 
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
You can only compare two dates at a time, so you must compare the first two dates to determine which is greatest, then compare this greater date with the third date, again to find the greater value. Finally, repeat this process with the fourth date, to find the greatest value overall.
You can use the getTime() function of the java.util.Date class to obtain "the number of milliseconds since January 1, 1970, 00:00:00 GMT represented by this Date object" as a long value, this will allow you to compare the dates easily.
Hope this helps,
Dave
[ July 07, 2003: Message edited by: Dave Turner ]
 
saran ram
Ranch Hand
Posts: 69
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you Dave,
I was successful in comparing 4 date values.
But I may get a requirement to compare more than 4 date values in near future.
so if there is someway to do this, reply me with some suggestions.
(i'm trying to use a hashtable or list & use collections methods, but yet to
suceed).
with regards,
Saran Ram
 
Bartender
Posts: 1844
Eclipse IDE Ruby Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Put the Dates in an array and sort the array using java.util.Arrays.sort(Object []). Dates implement Comperable, so you should get a sorted array of dates. The last one in the array is the most recent (greatest)
 
reply
    Bookmark Topic Watch Topic
  • New Topic