Writing a Javascript programe to get difference between two dates.

vishalneeraj-24503
Posted by vishalneeraj-24503 under JavaScript category on | Points: 40 | Views : 348
Refer below Javascript function:-
function get_dates_difference() 
{
now = new Date();
newYear = new Date(2014,8,1);
secs = Math.round((now-newYear)/1000);
days = Math.floor(secs / 86400);
secs = days*86400;
hours = Math.floor(secs / 3600);
secs = hours*3600;
minutes = Math.floor(secs / 60);
secs = minutes*60;

document.write(days + " days, " + hours + " hours, " + minutes + " minutes, and " + secs + " seconds.");
}


Output:- 23 days, 552 hours, 33120 minutes, and 1987200 seconds.

Comments or Responses

Login to post response