Reputation: 4065
How can I compare these two date and time values:
date 1 = 2012-03-07 11:55:18
date 2 = 2012-01-02 11:02:44
and find the time difference between them?
Upvotes: 1
Views: 151
Reputation: 8530
you can get seconds difference with below code,you can convert that accordingly
var date1=new Date("2012-03-07 11:55:18");
var date2=new Date("2012-01-02 11:02:44");
var mSeconds=date1.getTime()-date2.getTime();
alert(mSeconds/1000);
Upvotes: 2
Reputation: 4837
You can create the two dates with the Javascript Date object and then compare them with the usual operators.
Upvotes: 0
Reputation: 6683
you can convert the date objects to timestamps like date1.getTime() and then use those timestamps to get difference in milliseconds
Upvotes: 0