Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

comparision between two dates

 
sreedhar
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have two dates one is start date and the other one is end date.
how to find which one is greater among the two dates? and if end date is less than start date i want to display one error message.

please any one help regarding the date validations.
thanks in advance
 
sven studde
Ranch Hand
Posts: 148
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1) getTime()


2) before()

[ October 14, 2006: Message edited by: sven studde ]
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Moved to Java In General (Intermediate)
 
Burkhard Hassel
Ranch Hand
Posts: 1274
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi cowboys,

the Date class implements Comparable, so it is also possible to use the compareTo method.
eg



Sven's probosal with the getTime() is more precise as you can obtain the exact milliseconds between the Date objects.
Anyway, when you want to determine days, hours and so on between the dates, you should get an instance of the Calendar class (also in java.util) and work with this.


Yours,
Bu.
[ October 14, 2006: Message edited by: Burkhard Hassel ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic