Page 1 of 1

Timetrouble

Posted: Tue Jul 19, 2005 9:00 am
by tores
Hi

Is the following the correct method of counting half hours between two timestamps...

Code: Select all

$half_hours = ($t1 - $t2) / 1800; // (1800 => half hour in seconds)
I think specially of the case when $t1 includes daylight savings time and $t2 doesn't. In that case I imagine i might get two half hours too much.

regards tores

Posted: Tue Jul 19, 2005 9:09 am
by Chris Corbyn
That always seems a borderline issue ;)

Timestamp is in seconds so yes it's 60*30 == 1800 seconds for half an hour.

If you're going to cut DST it's not going to change (I don't think) - the timestamp itself will still be the number of seconds since 00:00 01/01/1970) even if the actual time is something else i.e. the timestamp doesn't suddently jump 3600 seconds at 1am or whatever ;)

Posted: Tue Jul 19, 2005 9:13 am
by djot
-
So if $t1 is today 1600 and $t2 is today 1800
$t2-$t1 will be 7200 or 4 half hours.

$halfhours = ($t2 - $t1) / 1800;

I did not understand
I think specially of the case when $t1 includes daylight savings time and $t2 doesn't. In that case I imagine i might get two half hours too much.
Time is continously added with +1 per second.

djot
-