Я думаю, вы можете воспользоваться преимуществами встроенной функциональности.
Вот пример для сравнения дат в javascript
.
const first = +new Date(); // current date
const last = +new Date(2014, 10, 10); // old date
console.log(first);
console.log(last);
// comparing the dates
console.log(first > last);
console.log(first < last);