I need to compare two dates in Javascript, considering only the day (ie. not the time), but I don't want to mutate the original date objects.
I've come up with:
_isDayGreaterOrEqualThan(date1, date2) {
const dayDate1 = new Date(date1).setHours(0,0,0,0);
const comparableDate1 = new Date(dayDate1).getTime();
const dayDate2 = new Date(date2).setHours(0,0,0,0);
const comparableDate2 = new Date(dayDate2).getTime();
return comparableDate1 >= comparableDate2;
}
Is there any more efficient way to do this, without using external libraries?