Dates can easily be compared.

The following example compares today's date with January 14, 2100:

Example

let text = "";
const today = new Date();
const someday = new Date();
someday.setFullYear(2100, 0, 14);

if (someday > today) {
  text = "Today is before January 14, 2100.";
} else {
  text = "Today is after January 14, 2100.";
}
JavaScript counts months from 0 to 11. January is 0. December is 11.



Practice Excercise Practice now