|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2007-03-28 15:21 UTC] ctrlaltca at libero dot it
Description:
------------
It seems that the date() function "jumps over" sundays when converting timestamps not referring to midnight.
Similar to #461
Reproduce code:
---------------
<?php
$day=date("j");
$mo=date("n");
$year=date("Y");
for($i=6; $i>=0; $i--)
{
$a=mktime(0, 0, 0, $mo,$day, $year);
$b=date("r",$a);
$c=strtotime($b. "-" . $i . " day");
$curdate=date("Ymd",$c);
$d=date("r");
$e=strtotime($d. "-" . $i . " day");
$curdate2=date("Ymd",$e);
echo "\n|".$b."=".$d."|".$c."=".$e."|".$curdate."=".$curdate2."|";
}
?>
Expected result:
----------------
I expect this script to return the right "Ymd" dates of the last seven days.
Actual result:
--------------
It works:
|Wed, 28 Mar 2007 00:00:00 +0200=Wed, 28 Mar 2007 17:13:37 +0200|1175032800=1175094817|20070328!=20070328|
but when it finds a sunday, dates are shifted off of 1 day:
|Wed, 28 Mar 2007 00:00:00 +0200=Wed, 28 Mar 2007 17:13:37 +0200|1174773600=1174835617|20070324!=20070325|
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Fri Nov 28 07:00:01 2025 UTC |
First, thank you for the reply. I tried the script: |Sat, 31 Mar 2007 00:00:00 +0000=Sat, 31 Mar 2007 17:18:59 +0000|1174780800=1174843139|20070324 230000=20070325 171859| I understand that strtotime($d. "-1 day") is an alias for "-24 hours", and dst handling routines adds one more hour to compensate. Afaik summer time begins and ends at 1:00 a.m. Universal Time (GMT) in Europe, and at 2:00 a.m. localtime in the US. Other states do it at midnight (example: Chile). Trying this other script it seems that php updates the time at midnight: <?php $day=24; $mo=03; $year=2007; for($i=0; $i<=7; $i++) { $a=mktime(22, 0, 0, $mo,$day, $year); $b=date("r",$a); $c=strtotime($b. "+" . $i . " hour"); $curdate=date("Ymd His",$c); echo "\n|".$b."|".$c."|".$curdate."|"; } echo "\n"; ?> Do all we live in Chile? :) Or am i wrong again? Thank you again for your comment, i'll use gm* class of functions.I get the following correct output: |Sat, 24 Mar 2007 22:00:00 +0100|1174770000|20070324 220000 +0100 CET| |Sat, 24 Mar 2007 22:00:00 +0100|1174773600|20070324 230000 +0100 CET| |Sat, 24 Mar 2007 22:00:00 +0100|1174777200|20070325 000000 +0100 CET| |Sat, 24 Mar 2007 22:00:00 +0100|1174780800|20070325 010000 +0100 CET| |Sat, 24 Mar 2007 22:00:00 +0100|1174784400|20070325 030000 +0200 CEST| |Sat, 24 Mar 2007 22:00:00 +0100|1174788000|20070325 040000 +0200 CEST| |Sat, 24 Mar 2007 22:00:00 +0100|1174791600|20070325 050000 +0200 CEST| |Sat, 24 Mar 2007 22:00:00 +0100|1174795200|20070325 060000 +0200 CEST| after modifying your date line to: $curdate=date("Ymd His O T",$c);