Anyone please help me to find the duration between two date-times in following format?

format is
Date1="23-03-2012 04:25PM"
Date2="26-09-2013 08:26AM"

I want to find out the diffence between Date1 and Date2 in following format.

The Result ="no of Years:no of Days:no of Hours:no of Mintues:no of Seconds"


you need to discover the difference in milliseconds and then convert to the unit you want.

Something like this:

// Constants
var minutes = 1000 * 60;
var hours   = minutes * 60;
var days    = hours * 24;
var years   = days * 365;

// Dates
var Date1= new Date("23-03-2012 04:25PM");
var Date2= new Date("26-09-2013 08:26AM");

// Datediff in milliseconds
var dif = Date2.getTime() - Date1.getTime();

// Convert to years
var difYears = Math.round(dif/years);
// Convert to days (subtracting the years)
var difDays = Math.round(dif/days) - (difYears * 365);

alert("Date diff: " + difYears + "year(s) and " + difDays + " day(s)" );

Hope it helps.

Be a part of the DaniWeb community

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