Quantcast
Channel: PHP Freaks: PHP Help
Viewing all articles
Browse latest Browse all 13200

Problem with strtotime

$
0
0

I have a script which calculates how many hours a truck driver has worked/rested in increments of 15 minutes.

 

For a given number of hours I loop around adding 15 minutes to a cursor for each 15 minutes of work/rest.

 

This all works fine until 7 Oct 2012 when adding 15 minutes to 01:45:00 gives a result of 03:00:00 instead of 02:00:00

 

Here's my code:

<?php

$diff = 4; // Number of hours difference in units of 15 minutes
$cursor = "2012-10-07 00:00:00"; // Start time, midnight on 07 October 2012
for($z=0;$z<$diff/.25;$z++) {
	print "Cursor = ".$cursor."<br>";
	$cursor = date('Y-m-d H:i:s', strtotime( "$cursor + 15 minutes" ));
}
?>

This is the result:

 

Cursor = 2012-10-07 00:00:00
Cursor = 2012-10-07 00:15:00
Cursor = 2012-10-07 00:30:00
Cursor = 2012-10-07 00:45:00
Cursor = 2012-10-07 01:00:00
Cursor = 2012-10-07 01:15:00
Cursor = 2012-10-07 01:30:00
Cursor = 2012-10-07 01:45:00 /* Jumps to 03:00:00 instead of 02:00:00 */
Cursor = 2012-10-07 03:00:00
Cursor = 2012-10-07 03:15:00
Cursor = 2012-10-07 03:30:00
Cursor = 2012-10-07 03:45:00
Cursor = 2012-10-07 04:00:00
Cursor = 2012-10-07 04:15:00
Cursor = 2012-10-07 04:30:00
Cursor = 2012-10-07 04:45:00

 

Can anyone help??


Viewing all articles
Browse latest Browse all 13200

Trending Articles