php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #73633 fourth day {Month} {Year} returning fifth day
Submitted: 2016-12-01 13:54 UTC Modified: 2016-12-01 15:09 UTC
From: php at rcs dot us Assigned:
Status: Not a bug Package: Date/time related
PHP Version: Irrelevant OS: All
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 this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: php at rcs dot us
New email:
PHP Version: OS:

 

 [2016-12-01 13:54 UTC] php at rcs dot us
Description:
------------
---
From manual page: http://www.php.net/datetime.formats.relative
---

While no specific example on this is in the manual, "fourth day July 2016" returns July 5th.

It's not specific to the fourth, any day is returning plus one.


Test script:
---------------
$firstDayJuly2016 =  new DateTime("first day July 2016");

// The following returns
// object(DateTime)
// public 'date' => string '2016-07-02 00:00:00' (length=19)

var_dump($firstDayJuly2016);

$fourthDayJuly2016 =  new DateTime("fourth day July 2016");

// The following returns
// object(DateTime)
// public 'date' => string '2016-07-05 00:00:00' (length=19)

var_dump($fourthDayJuly2016);

die;

Expected result:
----------------
I believe the expectation is that the "fourth day July 2016" would return July 2016-07-04.

Actual result:
--------------
"fourth day July 2016" returns July 2016-07-05.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2016-12-01 14:19 UTC] cmb@php.net
-Status: Open +Status: Verified -Type: Bug +Type: Documentation Problem
 [2016-12-01 14:19 UTC] cmb@php.net
To get the first day of the month you have to use `first day of July 2016` (note the "of"). `fourth day` is identical to `4 days` which is identical to `+4 days`, so `fourth day of July 2016` is identical to `July 2014 +4 days`, see <https://3v4l.org/pSsLn>. Thus, the behavior is expected, but the documentation could be improved.
 [2016-12-01 15:09 UTC] salathe@php.net
-Status: Verified +Status: Not a bug
 [2016-12-01 15:09 UTC] salathe@php.net
This is correct behaviour as already documented under the relative date formats section.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Jun 02 06:01:28 2024 UTC