php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #48291 Sttotime returning wrong dates
Submitted: 2009-05-15 11:01 UTC Modified: 2009-05-15 11:19 UTC
From: rob at guidamedia dot com Assigned:
Status: Not a bug Package: Scripting Engine problem
PHP Version: 5.2.9 OS: iis
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: rob at guidamedia dot com
New email:
PHP Version: OS:

 

 [2009-05-15 11:01 UTC] rob at guidamedia dot com
Description:
------------
When converting weeks and days to a date using strtotime, some months return the wrong dates. For instance, strtotime("first thursday", mktime(0,0,0,11,1,2009)) returns 11/4/2009, which is a wednesday. There are also issues using "last".

This seems to be happening with November 2009. I am not sure about other years or other months. I think I had issues there as well, but infrequently. I tried seeing if the issue is with any month when the first day of the month is sunday, but it does not appear to be the case.

I am creating a new function to handle strtotime in this manner, because I found more issues with using this function and creating a series of dates that are incremented by a year.


Reproduce code:
---------------
public function getDateFromWeekAndDayOfMonth($d, $m, $y){
$fistDayOfMonth = mktime(0, 0, 0, $m, 1, $y)
$firstWeekForDay = strtotime("first " . $d, $fistDayOfMonth);
return $firstWeekForDay;
}


Expected result:
----------------
For the First Thursday in November 1, 2009, I expect to have the datetime for 11-5-2009.

Actual result:
--------------
11-4-2009

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2009-05-15 11:19 UTC] jani@php.net
Please do not submit the same bug more than once. An existing
bug report already describes this very problem. Even if you feel
that your issue is somewhat different, the resolution is likely
to be the same. 

Thank you for your interest in PHP.


 
PHP Copyright © 2001-2026 The PHP Group
All rights reserved.
Last updated: Fri Feb 06 17:00:02 2026 UTC