← Snippets

isDateBefore

Added December 27, 2020

Compares two vanilla Javascript Date objects. Returns true is the first date falls before the second.

1function isDateBefore(date1, date2) {
2 if (date1.getFullYear() < date2.getFullYear()) {
3 return true
4 }
5 if (date1.getMonth() < date2.getMonth()) {
6 return true
7 }
8 if (date1.getDate() < date2.getDate()) {
9 return true
10 }
11 return false
12}
13