|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2008-01-03 16:42 UTC] phreaks at gmail dot com
Description:
------------
When adding days to a date returns wrong weekday.
This only happens when adding days to 12-31-07.
Workaround is handle any new year dates by starting from 1-1-08 and adding days.
Reproduce code:
---------------
$fm = 12;
$day = 31;
for ($i = 0; $i < 7; $i++)
echo date("M-d (w)", mktime(1,1,1,$fm,$day++))."<BR>";
Expected result:
----------------
Expected output
Dec-31 (1)
Jan-01 (2)
Jan-02 (3)
Jan-03 (4)
Jan-04 (5)
Jan-05 (6)
Jan-06 (0)
Actual result:
--------------
The output of above is:
Dec-31 (3)
Jan-01 (4)
Jan-02 (5)
Jan-03 (6)
Jan-04 (0)
Jan-05 (1)
Jan-06 (2)
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sat Nov 08 20:00:02 2025 UTC |
There is no bug here: $fm = 12; $day = 31; echo date("M-d (w)", mktime(1,1,1,$fm,$day)), "\n"; shows correctly: Dec-31 (3) You don;t specify the year to mktime, so it assumes the current one, which is now 2008. Your output is correct for the year 2007. Change your code to this to see it: $fm = 12; $day = 31; for ($i = 0; $i < 7; $i++) echo date("M-d Y (w)", mktime(1,1,1,$fm,$day++))."\n";