0

I want to compare following to dates i.e. d1 with d2:

var d1 = new Date(12,05,2013);
var d2 = "12/05/2013";
4

2 Answers 2

4

convert date to timestamp

DateObject.getTime(); will give timestamp

and convert string to date new Date(d2)

javScript

var d1 = new Date("12/05/2013");
var d2 = "12/05/2013";
console.log(d1.getTime());
console.log(new Date(d2).getTime());

if(d1.getTime() == new Date(d2).getTime()){
   //do something
}
Sign up to request clarification or add additional context in comments.

Comments

0

To compare two variables you need to use JS operators, consider:

if(d1==d2)
{
 //do this
}

else
{
 //do this
}

More information on logical operators can be found here: http://www.w3schools.com/js/js_comparisons.asp

1 Comment

OP's d1 object will never compare equal to his d2 string like that.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.