0

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"

2
Contributors
1
Reply
2
Views
5 Years
Discussion Span
Last Post by AleMonteiro
0

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.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.