Determining Date Equality in Javascript Determining Date Equality in Javascript javascript javascript

Determining Date Equality in Javascript


Use the getTime() method. It will check the numeric value of the date and it will work for both the greater than/less than checks as well as the equals checks.

EDIT:

if (d1.getTime() === d2.getTime())


If you don't want to call getTime() just try this:

(a >= b && a <= b)


var d1 = new Date($('#datein').val());var d2 = new Date($('#dateout').val());

use two simple ways to check equality

  1. if( d1.toString() === d2.toString())
  2. if( +d1 === +d2)