Click Here To Get Amazing Facebook Profile Covers,Status Messages

How to compare two dates in jsp

If you want to perform some sort of date comparison in jsp then you need java.util.Date class methods.The two dates in jsp can not be compared using logical operators(<,>,=).

The simplest one is to use compareTo method of java.util.Date class in order to compare two date objects in jsp.

Depending on date values compareTo() returns 3 different numeric value.
date1.compareTo(date2)
It returns 0 if dates are equal
It returns 1, if first date is greater than second date
It returns -1, if first date is less than second date

As an alternate option you can use after,before or equals methods of Date class.

date1.after(date2)
returns a Boolean value TRUE if Date1 is greater than date2

date1.before(date2)
returns a Boolean value TRUE if Date1 is less than date2

date1.equals(date2)
returns a Boolean value TRUE if Date1 is equal to date2