php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #60340 DateTime. The problem of determining the relative dates, by the command last
Submitted: 2011-11-19 18:58 UTC Modified: 2011-11-19 21:33 UTC
From: marcingronowski at gmail dot com Assigned:
Status: Not a bug Package: Date/time related
PHP Version: 5.3.8 OS: Windows
Private report: No CVE-ID: None
 [2011-11-19 18:58 UTC] marcingronowski at gmail dot com
Description:
------------
Incorrect data is generated by function DateTime::__construct in case of using the 
relative definition of time.

If you use the command "last day of month" the previous month will be returned.
If you use the command "first day of month" the correct month will be returned and 
second day in the month will be returned.

Test script:
---------------
$datea = new DateTime('last day October 2011');
echo $datea->format('Y-F-d');

$dateb = new DateTime('last monday October 2011');
echo $dateb->format('Y-F-d');

$datec = new DateTime('first day October 2011');
echo $datec->format('Y-F-d');

$datec = new DateTime('first day November 2011');
echo $datec->format('Y-F-d');


Expected result:
----------------
2011-October-30
2011-October-30
2011-October-01
2011-November-01


Actual result:
--------------
2011-September-30
2011-September-26
2011-October-02
2011-November-02

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2011-11-19 21:33 UTC] salathe@php.net
-Status: Open +Status: Bogus
 [2011-11-19 21:33 UTC] salathe@php.net
You aren't testing "first/last day of", you're testing "first/last day" which 
simply moves the date defined by the absolute parts forward/backward by one day.  
The same applies to your "last monday" test, which should be "last monday of".

All of these behaviours are documented.
 [2011-11-20 00:22 UTC] marcingronowski at gmail dot com
@ salathe@php.net

You're right. I'm sorry. It's my fault.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Tue Jul 15 07:01:31 2025 UTC