php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #64448 DATE Day of Week bug for 3-10-2013
Submitted: 2013-03-18 20:47 UTC Modified: 2013-03-18 21:05 UTC
From: xojins at gmail dot com Assigned:
Status: Not a bug Package: Date/time related
PHP Version: 5.3.23 OS: RedHat EL5
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: xojins at gmail dot com
New email:
PHP Version: OS:

 

 [2013-03-18 20:47 UTC] xojins at gmail dot com
Description:
------------
When using the DATE function and returning the day of the week (lowercase L 
format) returns the wrong day of the week for 3/10/2013.

The example provided shows subtracting 86400 seconds from strtotime('03/11/2013') 
to return 1362888000 seconds. When passed to DATE, it returns Saturday. This is 
wrong and should be Sunday.

You need to add 3600 to any value to calculate 3/10/13 correctly.


Test script:
---------------
$d1 = date('l', strtotime('03/12/2013')-(60*60*24));  //date('l', 1363060800 - 86400) = date('l', 1362974400) = Monday

$d2 =date('l', strtotime('03/11/2013')-(60*60*24));  //date('l', 1362974400 - 86400) = date('l', 1362888000) = Saturday != date('m-d-y', 1362888000)

$d3 =date('l', strtotime('03/10/2013')-(60*60*24));  //date('l', 1362891600 - 86400) = date('l', 1362805200) = Saturday 

echo $d1 . '<br>';
echo $d2 . '<br>';
echo $d3 . '<br>';

Expected result:
----------------
Monday
Sunday
Saturday

Actual result:
--------------
Monday
Saturday
Saturday

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2013-03-18 20:56 UTC] aharvey@php.net
-Status: Open +Status: Feedback
 [2013-03-18 20:56 UTC] aharvey@php.net
Which time zone is PHP configured to operate in (ie what do you get if you echo date_default_timezone_get())?
 [2013-03-18 20:59 UTC] xojins at gmail dot com
I have tested this with the following timezones:
America/New_York
US/Pacific

Also tested with PHP 5.4.12 and 5.5.0 alpha 5. All exhibit the same symptom.
 [2013-03-18 20:59 UTC] xojins at gmail dot com
-Status: Feedback +Status: Open
 [2013-03-18 21:03 UTC] aharvey@php.net
-Status: Open +Status: Not a bug
 [2013-03-18 21:03 UTC] aharvey@php.net
This is due to daylight saving starting on March 10 in both of those time zones: March 10 only had 23 hours, so subtracting 24 hours from 12:00 am on March 11 results in $d2 being 11 pm on March 9.
 [2013-03-18 21:05 UTC] rasmus@php.net
You have discovered DST. You can't assume all days will have 86400 seconds. PHP 
is correct here.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Wed Jul 02 14:01:36 2025 UTC