php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #40003 strtotime(), incorrect results
Submitted: 2007-01-02 23:15 UTC Modified: 2007-01-03 20:32 UTC
From: matt at iws dot co dot nz Assigned:
Status: Not a bug Package: Date/time related
PHP Version: 5.2.0 OS: Linux 2.4
Private report: No CVE-ID: None
 [2007-01-02 23:15 UTC] matt at iws dot co dot nz
Description:
------------
Asking strtotime() for the date of the first occurrence of a particular day of the week, when that day of the week is also the first day of the month, returns the incorrect day. See examples below.




Reproduce code:
---------------
echo date('Y-m-d', strtotime('first monday jan 2007'));

echo date('Y-m-d', strtotime('first monday feb 2007'));  

echo date('Y-m-d', strtotime('first thursday feb 2007'));

echo date('Y-m-d', strtotime('first thursday jan 2007')); 

Expected result:
----------------
// First Monday Jan 2007
2007-01-01

// First Monday Feb 2007
2007-02-05

// First Thursday Feb 2007
2007-02-01

// First Thursday Jan 2007
2007-01-04

Actual result:
--------------
// First Monday Jan 2007 - incorrect
2007-01-08

// First Monday Feb 2007 - correct
2007-02-05

// First Thursday Feb 2007 - incorrect
2007-02-08

// First Thursday Jan 2007 - correct
2007-01-04

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2007-01-03 08:08 UTC] derick@php.net
This is not a bug, but expected behaviour. To get the behaviour that you want, simply use "Monday Jan 2007" (without the first).
 [2007-01-03 20:32 UTC] matt at iws dot co dot nz
Shouldn't "Second Monday Jan 2007" and "Second Tuesday Jan 2007" return days consecutive days in Jan 2007, instead of dates one week apart? 

"Second Monday Feb 2007" and "Second Tuesday Feb 2007" return the correct results. As far as I can tell the results are always inconsistent for the weekday that is the first day of the month.

Example Code:
-------------
echo date('Y-m-d', strtotime('second monday jan 2007')); // returns 2007-01-15
echo date('Y-m-d', strtotime('second tuesday jan 2007')); // returns 2007-01-09
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Nov 08 15:01:30 2024 UTC