Mar Cejas Mar Cejas - 2 months ago 8
Javascript Question

javascript calculate number of days

I'm having hard time to get the right solution for this, so I need your help now.

date1 = "03/02/2012 09:51 pm"

date2 = "03/04/2012 06:00 pm"


Calculate the above example date into how many days diff. using JavaScript.

Answer
var date1 = Date.parse("03/02/2012 09:51 pm");
var date2 = Date.parse("03/04/2012 06:00 pm");

var dayDiff = (date2 / (1000*60*60*24)) - (date1 / (1000*60*60*24));
Comments