Bug #68973 [Opn->Nab]: DateTime('first day of last week') not working
Edit report at https://bugs.php.net/bug.php?id=68973&edit=1
ID: 68973
Updated by: aharvey@php.net
Reported by: t dot baumgarden at web dot de
Summary: DateTime('first day of last week') not working
-Status: Open
+Status: Not a bug
Type: Bug
Package: Date/time related
Operating System: centOS
PHP Version: 5.5.21
Block user comment: N
Private report: N
New Comment:
What cmbecker69 said. :)
Previous Comments:
------------------------------------------------------------------------
[2015-02-02 21:41:43] cmbecker69 at gmx dot de
According to the table "Day-based notations" on the manual page
"Relative Formats"[1] "first day of" and "last day of" are always
relative a *month*.
What you're looking for is
new DateTime('Monday of last week')
resp.
new DateTime('Sunday of last week')
[1] <http://php.net/manual/en/datetime.formats.relative.php>
------------------------------------------------------------------------
[2015-02-02 16:42:06] t dot baumgarden at web dot de
Description:
------------
Today is 2015-02-02 (02.February)
I want first and last day ob last week:
$date = new DateTime('first day of last week');
echo $date->format('Y-m-d');
// ---
$date = new DateTime('last day of last week');
echo $date->format('Y-m-d');
result is (WRONG!):
2015-02-01
2015-02-28
MUST BE:
2015-01-26
2015-02-01
This working fine with "month" instead "week":
DateTime('first day of last month');
DateTime('last day of last month');
result is:
2015-01-01
2015-01-31
Test script:
---------------
$date = new DateTime('first day of last week');
echo $date->format('Y-m-d');
$date = new DateTime('last day of last week');
echo $date->format('Y-m-d');
Expected result:
----------------
2015-01-26
2015-02-01
Actual result:
--------------
2015-02-01
2015-02-28
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=68973&edit=1
Thread (4 messages)