php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #67853 strtotime() incorrect handles relative dates
Submitted: 2014-08-17 19:34 UTC Modified: 2014-08-18 03:41 UTC
From: bugs at oliverboorman dot biz Assigned:
Status: Not a bug Package: Date/time related
PHP Version: Irrelevant OS: Windows
Private report: No CVE-ID: None
 [2014-08-17 19:34 UTC] bugs at oliverboorman dot biz
Description:
------------
When passing date strings such as "second Saturday August 2015" to strtotime(), the wrong output is returned. The "first", "second" or "third" qualifiers seem to use the wrong index in certain cases.

For example, in 2015, the first day of August will be a Saturday so this should be considered the first Saturday of August. However, the function seems to treat it as the zeroth Saturday.

Test script:
---------------
$test = strtotime("second Saturday August 2015");
echo date("d M Y h:i" $test);

Expected result:
----------------
08 Aug 2015 12:00

Actual result:
--------------
15 Aug 2015 12:00

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2014-08-17 19:58 UTC] bugs at oliverboorman dot biz
On the doc page for the strtotime() function (http://uk3.php.net/manual/en/function.strtotime.php), it is mention that:

"In PHP 5 prior to 5.2.7, requesting a given occurrence of a given weekday in a month where that weekday was the first day of the month would incorrectly add one week to the returned timestamp. This has been corrected in 5.2.7 and later versions." 

However, this issues is observable on version 5.2.14.
 [2014-08-18 03:41 UTC] rasmus@php.net
-Status: Open +Status: Not a bug
 [2014-08-18 03:41 UTC] rasmus@php.net
You actually have to use complete expressions here. It is an English-parsing function and in English you would say, "second saturday of August 2015" in which case you get your expected result.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri May 17 09:01:32 2024 UTC