Hi..

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"

Hi,

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 developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.