when comparing two dates with date before method, if the dates are similar it returns false as follows:
date1.equals(date2), it is normal that
date1.before(date2) returns false. As will do
Both dates are the same, so one is not before the other.
From javadoc : true if and only if the instant of time represented by this Date object is strictly earlier than the instant represented by when; false otherwise.
Try something like :
if(date1.before(date2) || date1.equals(date2)) ...
Answers provided below suggest testing for the inverse, and they're right:
Both tests are equivalent (some quick tests didn't even show a significant performance gap, but the gap is always to the advantage of the second one).