Java Utililty Methods Date Compare by Day

List of utility methods to do Date Compare by Day

Description

The list of methods to do Date Compare by Day are organized into topic(s).

Method

booleanisSameDay(Date a, Date b)
is Same Day
a = truncDate(a);
b = truncDate(b);
return equals(a, b);
booleanisSameDay(Date a, Date b)
is Same Day
Date normDateA = dateStart(a);
Date normDateB = dateStart(b);
return normDateA.equals(normDateB);
booleanisSameDay(Date d1, Date d2)
is Same Day
if (d1 != null && d2 != null) {
    Calendar c1 = Calendar.getInstance();
    c1.setTime(d1);
    int n1 = c1.get(Calendar.DAY_OF_YEAR) + c1.get(Calendar.YEAR);
    c1.setTime(d2);
    int n2 = c1.get(Calendar.DAY_OF_YEAR) + c1.get(Calendar.YEAR);
    return n1 == n2;
return false;
booleanisSameDay(Date d1, Date d2)
Compares two dates.
calendar1.setTime(d1);
calendar2.setTime(d2);
return isSameDay();
booleanisSameDay(Date d1, Date d2)
is Same Day
return getDateWithoutTimePart(d1).compareTo(getDateWithoutTimePart(d2)) == 0;
booleanisSameDay(Date date)
is Same Day
Calendar calendar = Calendar.getInstance();
Calendar startCalendar = Calendar.getInstance();
startCalendar.setTime(date);
return calendar.get(Calendar.DATE) == startCalendar.get(Calendar.DATE);
booleanisSameDay(Date date1, Date date2)
is Same Day
if (date1 == null && date2 == null) {
    return true;
if (date1 == null || date2 == null) {
    return false;
Calendar cal1 = getCalendar(getDate(date1));
Calendar cal2 = getCalendar(getDate(date2));
...
booleanisSameDay(Date date1, Date date2)
is Same Day
if (date1 == null && date2 == null)
    return true;
if (date1 == null || date2 == null)
    return false;
Calendar cal1 = GregorianCalendar.getInstance();
cal1.setTime(date1);
Calendar cal2 = GregorianCalendar.getInstance();
cal2.setTime(date2);
...
booleanisSameDay(Date date1, Date date2)

Checks if two date objects are on the same day ignoring time.

28 Mar 2002 13:45 and 28 Mar 2002 06:01 would return true.

if (date1 == null || date2 == null) {
    throw new IllegalArgumentException("The date must not be null");
Calendar cal1 = Calendar.getInstance();
cal1.setTime(date1);
Calendar cal2 = Calendar.getInstance();
cal2.setTime(date2);
return isSameDay(cal1, cal2);
...
booleanisSameDay(Date day1, Date day2)
Checks if it is the same day in both dates
if (day1 == null || day1 == null) {
    throw new IllegalArgumentException("The date must not be null");
Calendar cal1 = Calendar.getInstance();
cal1.setTime(day1);
Calendar cal2 = Calendar.getInstance();
cal1.setTime(day2);
return (cal1.get(Calendar.ERA) == cal2.get(Calendar.ERA)
...