To compare dates in JavaScript, use the regular
>
, >=
, <
, <=
operators.Here's how you do it:
const pastDate = new Date(2000, 1, 1);
const futureDate = new Date(2300, 1, 1);
// Past is before Future: true
console.log('Past is before Future:', pastDate < futureDate);
// Future is after Past: true
console.log('Future is after Past:', futureDate > pastDate);