...

View Full Version : Difference between two datetime



Nirbhay
06-01-2009, 10:12 AM
Hi All ,


I need to find out the difference between two date times like
$logged_time='2009-06-01 01:38:35';
$current_time='2009-06-01 07:48:45';

I need the differnce between $logged_time and $current_time

can any one help me ...

Thanx

venegal
06-01-2009, 12:41 PM
Are you sure this is a Javascript question? The format of your variables suggest PHP.

mrhoo
06-01-2009, 02:14 PM
If you do need to handle ISO time formats with javascript, just remember that they refer to GMT time to seconds, and months are 1-12.

Javascript Dates are local and to milliseconds, and months range from 0-11.

A bulletproof method to convert ISO to a javascript date would have to include a switch for the
short versions that use year, week in year and day in week, and the year and day in year formats,
but this will handle the common long format you show:


Date.fromISO= function(s){
var i= 0, A= s.split(/\D+/);
while(i++<7){
if(!A[i]) A[i]= 0;
else A[i]= parseInt(A[i], 10);
}
--A[1];
return new Date(Date.UTC(A[0], A[1], A[2], A[3], A[4], A[5]));
}

var s1='2009-06-01 01:38:35';
var s2='2009-06-01 07:48:45';
alert((Date.fromISO(s2)-Date.fromISO(s1))/1000+' seconds');



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum