Timetrouble

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
tores
Forum Contributor
Posts: 120
Joined: Fri Jun 18, 2004 3:04 am

Timetrouble

Post 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
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post 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 ;)
djot
Forum Contributor
Posts: 313
Joined: Wed Jan 14, 2004 10:21 am
Location: planet earth
Contact:

Post 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
-
Post Reply