|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2012-05-06 11:30 UTC] francois dot dambrine at isen-lille dot fr
Description:
------------
As I was testing a script where I need to get the second day of previous month I
found out this issue : I can't get this day with that phrase.
With larger tests I got the issue for every "ordinal" keyword apart from "first"
and "last".
Test script:
---------------
date_default_timezone_set('Europe/Paris');
$firstDay = new DateTime('first day of previous month');
echo $firstDay->format('l').PHP_EOL;
$lastDay = new DateTime('last day of previous month');
echo $lastDay->format('l').PHP_EOL;
$secondDay = new DateTime('second day of previous month');
echo $secondDay->format('l').PHP_EOL;
$thirdDay = new DateTime('third day of previous month');
echo $thirdDay->format('l').PHP_EOL;
Expected result:
----------------
Sunday
Monday
Monday
Tuesday
Actual result:
--------------
Sunday
Monday
PHP Fatal error: Uncaught exception 'Exception' with message
'DateTime::__construct(): Failed to parse time string (second day of previous
month) at position 11 (o): The timezone could not be found in the database' in
/home/isen/essai.php:7
Stack trace:
#0 /home/isen/essai.php(7): DateTime->__construct('second day of p...')
#1 {main}
thrown in /home/isen/essai.php on line 7
Fatal error: Uncaught exception 'Exception' with message
'DateTime::__construct(): Failed to parse time string (second day of previous
month) at position 11 (o): The timezone could not be found in the database' in
/home/isen/essai.php:7
Stack trace:
#0 /home/isen/essai.php(7): DateTime->__construct('second day of p...')
#1 {main}
thrown in /home/isen/essai.php on line 7
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Wed Oct 22 08:00:01 2025 UTC |
This is just not implemented. For you now, you'll have to do: $firstDay = new DateTime('first day of previous month'); $firstDay->modify( 'next day' );