user4323627
user4323627

Reputation:

Date issues in JavaScript

The code below mentioned is for comparision of date. Both date1 and mydate have similar values,But if i compare its not entering if loop. Any help appreciated

 var date_arr = new Array( "Jan", "Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec");
var Avl_date =  document.getElementById("Available_Date").value;
var V_date1 = Avl_date.split('-');
var date1 = new Date (V_date1[2], date_arr.indexOf(V_date1[1]),V_date1[0]);

var myDate = new Date(); 
myDate.setHours(0,0,0);

 //Thu Dec 04 2014 00:00:00 GMT+0530 (IST) --> date1
 //Thu Dec 04 2014 00:00:00 GMT+0530 (IST) --> mydate

 if(myDate.getTime() === date1.getTime())
{
  //Not entering the loop
}

Upvotes: 1

Views: 42

Answers (2)

hint
hint

Reputation: 51

Barmar is correct. setting the milliseconds will solve your problem.

Upvotes: 0

Barmar
Barmar

Reputation: 780851

You're not setting the milliseconds of myDate to 0, so it keeps its original milliseconds. Use:

myDate.setHours(0,0,0,0);

Upvotes: 2

Related Questions