time Difference between two dates

if
var a=‘2014-03-23 23:33:33’
var b=‘2014-03-23’ 04:44:44’
using Jquery

var c=b-a; c should br 12:23:00

What have you tried? What was the result?

Try this: http://bit.ly/1i8iplw

Also, You cannot subtract var a from var b and the time difference is not 12 hours, it is 18 hours and 49 minutes. Since you have the same calendar date, eleven at night does not come before four in the morning of the same date.

Fiddle me this http://jsfiddle.net/e87yL/30/

[php] start_time = new Date(“2014-03-23T04:44”);
end_time = new Date(“2014-03-23T23:33”);

var diff = end_time - start_time;

var diffSeconds = diff/1000;
var HH = Math.floor(diffSeconds/3600);
var MM = Math.floor(diffSeconds%3600)/60;

var formatted = ((HH < 10)?("0" + HH):HH) + ":" + ((MM < 10)?("0" + MM):MM)
 alert(formatted);[/php]
Sponsor our Newsletter | Privacy Policy | Terms of Service