note 41495 added to ref.datetime
| From: | nickaubert at america'sbiggestisp dot com | Date: | Mon, 12 Apr 2004 17:13:34 +0000 |
| Subject: | note 41495 added to ref.datetime | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-68029@lists.php.net to get a copy of this message | ||
I ran into an issue using a function that loops through an array of dates where the keys to the
array are the Unix timestamp for midnight for each date. The loop starts at the first timestamp,
then incremented by adding 86400 seconds (ie. 60 x 60 x 24). However, Daylight Saving Time threw
off the accuracy of this loop, since certain days have a duration other than 86400 seconds. I
worked around it by adding a couple of lines to force the timestamp to midnight at each interval.
<?php
$ONE_DAY = 90000; // can't use 86400 because some days have one hour more or less
for ( $each_timestamp = $start_time ; $each_timestamp <= $end_time ; $each_timestamp +=
$ONE_DAY) {
/* force midnight to compensate for daylight saving time */
$this_timestamp_array = getdate( $each_timestamp );
$each_timestamp = mktime ( 0 , 0 , 0 , $this_timestamp_array[mon] , $this_timestamp_array[mday]
, $this_timestamp_array[year] );
// do some stuff...
}
?>
----
Manual Page -- http://www.php.net/manual/en/ref.datetime.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+41495
Delete -- http://master.php.net/manage/user-notes.php?action=delete+41495&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+41495&report=yes
Search -- http://master.php.net/manage/user-notes.php