Javascript - Date Compare Dates

Introduction

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

Demo

var today, someday, text;
today = new Date();/*  w ww  .  j av  a 2s . co  m*/
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.";
}
console.log(text);

Result

JavaScript counts months from 0 to 11. January is 0. December is 11.

Related Topic