php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #50249 ordinal month days don't work
Submitted: 2009-11-20 18:18 UTC Modified: 2017-02-12 20:36 UTC
Votes:4
Avg. Score:4.0 ± 1.0
Reproduced:4 of 4 (100.0%)
Same Version:2 (50.0%)
Same OS:2 (50.0%)
From: jennifer dot kimball at nrc dot ca Assigned: derick (profile)
Status: Assigned Package: Date/time related
PHP Version: 5.3.1 OS: Solaris 10
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: jennifer dot kimball at nrc dot ca
New email:
PHP Version: OS:

 

 [2009-11-20 18:18 UTC] jennifer dot kimball at nrc dot ca
Description:
------------
It appears impossible to write an expression that will generate the Nth day of any month (except for first or last days).

Expressions like "third day of next month" fail in date_create().
Expressions like "next month +3 days" increment the month number and add 3 days to the current day number.
Expressions like "first day of next month +2 days" give just the first day of the month.



Reproduce code:
---------------
//today is Nov 20, 2009

$d1=date_create('third day of next month');
print_r(DateTime::getLastErrors()); //errors
echo 'd1: ',$d1->format('Y-m-d'); //nothing output

$d2=date_create('first day of next month');
echo 'd2: ',$d2->format('Y-m-d'); //2009-12-01, works as expected

$d3=date_create('first day of next month +2 days');
echo 'd3: ',$d3->format('Y-m-d'); //2009-12-01, not 2009-12-03

$d4=date_create('next month +3 days');
echo 'd4: ',$d4->format('Y-m-d'); //2009-12-23, also not 2009-12-03 though I can understand why



Expected result:
----------------
Array
(
    [warning_count] => 0
    [warnings] => Array
        (
        )

    [error_count] => 0
    [errors] => Array
        (
        )

)
d1: 2009-12-03

d2: 2009-12-01

d3: 2009-12-03

d4: 2009-12-23

Actual result:
--------------
Array
(
    [warning_count] => 0
    [warnings] => Array
        (
        )

    [error_count] => 1
    [errors] => Array
        (
            [10] => The timezone could not be found in the database
        )

)
d1: 

d2: 2009-12-01

d3: 2009-12-01 //still the 1st, 2 days not added

d4: 2009-12-23

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2009-11-23 13:05 UTC] sjoerd@php.net
Thank you for your bug report.

Here is a piece of code which may do what you want:
<?php
$current_month = date('m');
$fourth_day = mktime(0, 0, 0, $current_month + 1, 4);
echo date('c', $fourth_day);
?>
 [2009-11-23 13:41 UTC] derick@php.net
I'll see if we can support this in some way without breaking anything else— please ignore what Sjoerd wrote. mktime() and timestamps should be avoided!
 [2009-11-23 15:05 UTC] rasmus@php.net
I think a better way to do it currently is just to do it in 2 steps:

$d=date_create('first day of next month');
$d->modify("+2 days");

 [2009-11-24 12:55 UTC] jennifer dot kimball at nrc dot ca
Thanks for your suggestions. I wish you success in adding support for "date of next month" expressions. Thanks.
 [2010-03-07 14:10 UTC] derick@php.net
-Package: Date/time related +Package: Feature/Change Request
 [2010-03-07 14:10 UTC] derick@php.net
Changing this to a feature request.
 [2010-11-18 12:29 UTC] jani@php.net
-Package: Feature/Change Request +Package: Date/time related
 [2017-02-12 20:36 UTC] derick@php.net
-Type: Bug +Type: Feature/Change Request
 
PHP Copyright © 2001-2017 The PHP Group
All rights reserved.
Last updated: Sun Nov 19 01:31:42 2017 UTC