-4

Return the number of milliseconds between January 1, 1970 and given date.

Using Date.Parse Method to compare the Dates:

var fromdt="2013/05/29";
var todt="2013/05/29";
var d = Date.parse(fromdt);
var e = Date.parse(todt);
if(d==e)
{
    alert("Both the Dates are equal!");
}
else if(d>e)
{
    alert("From date should not be greater than todate!");
}
else if(d<e)
{
 alert("Valid Dates");
}

Also using - operator to compare the dates:

var dt_from = new Date("2013/05/25");
var dt_to=new Date("2013/05/24");

if(dt_from-dt_to == 0)
{
alert("Both dates are Equal!");
}
else if(dt_from-dt_to > 0)
{
alert("From date should not be greater than todate!");
}
else if(dt_from-dt_to < 0)
{
alert("Okay!");
}

Also this will provide the difference in milliseconds. Then, what is the difference between the 2 codes?I mean Date.parse and new Date()..Thank you....

Dylan
  • 137
  • 1
  • 2
  • 10

1 Answers1

1

Print following commands in browser console and you can see diference:

1) Date.parse("2013/05/29") //return number of milliseconds between January 1, 1970 https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/parse

2) new Date("2013/05/25") //return DateTime object