php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #61962 Relative format : second/third... not parsed
Submitted: 2012-05-06 11:30 UTC Modified: 2022-05-13 13:39 UTC
Votes:2
Avg. Score:3.0 ± 2.0
Reproduced:1 of 2 (50.0%)
Same Version:1 (100.0%)
Same OS:-1 (-100.0%)
From: francois dot dambrine at isen-lille dot fr Assigned: heiglandreas (profile)
Status: Closed Package: Date/time related
PHP Version: 5.4.2 OS: Ubuntu 11.10
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 you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: francois dot dambrine at isen-lille dot fr
New email:
PHP Version: OS:

 

 [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


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2012-05-11 15:47 UTC] zhanglijiu at gmail dot com
There is no parameter 'second,third day of previous month'.
 [2012-05-11 16:38 UTC] derick@php.net
-Package: Date/time related +Package: *General Issues
 [2012-05-11 16:38 UTC] derick@php.net
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' );
 [2016-06-14 11:41 UTC] cmb@php.net
-Type: Bug +Type: Feature/Change Request -Package: *General Issues +Package: Date/time related
 [2016-06-14 11:41 UTC] cmb@php.net
> This is just not implemented.

So I'm changing to feature request.
 [2017-01-13 07:03 UTC] heiglandreas@php.net
-Assigned To: +Assigned To: heiglandreas
 [2022-05-13 13:39 UTC] derick@php.net
-Status: Assigned +Status: Closed
 [2022-05-13 13:39 UTC] derick@php.net
I am closing this, as this would increase the parser complexity significantly, with a reasonable workaround available. If you have a really compelling case, feel free to add a ticket to https://github.com/php/php-src/issues, but it needs to have a really good reason for this to get added.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Wed Feb 05 08:01:30 2025 UTC