This is my time format:-

start_date = 20-01-2015 1:00 AM;
end_date = 25-03-2015 2:50 PM;

All these date fields are in a drop down. How can i calculate the number of days in between these dates using javscript?

Can anyone give me some code reference for this? i need to calculate the hours between these two dates

Thank You.

Hello Vishnu4,

Please try:

var oneDay = 24*60*60*1000; // hours*minutes*seconds*milliseconds
var start_date = new Date(2015,01,20,1,0); //year, month, day, hours, minutes, seconds, milliseconds
var end_date = new Date(2015,03,25,2,50); //year, month, day, hours, minutes, seconds, milliseconds

var diffDays = Math.round(Math.abs((start_date.getTime() - end_date.getTime())/(oneDay)));
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.