Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to compare just the day in a java date?

Tags:

java

date

I'm trying to do a simple date comparison between yesterday and today

if (yesterday.before(today)) {
 ...
}

The issue is that with the before method I will eval to true even if it's just a few seconds difference. How might I compare just the day (because I only want to eval this to true if it was the previous day (minutes/seconds should be ignored)

Thank you in advance

like image 852
Toran Billups Avatar asked Nov 28 '22 10:11

Toran Billups


1 Answers

using DateUtils -

if (!DateUtils.isSameDay(yesterday, today) && (yesterday.before(today)) {
   //...
}

EDIT: it can be done without DateUtils as well. See this thread.

like image 143
Praveen Lobo Avatar answered Dec 19 '22 23:12

Praveen Lobo