|   | php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login | 
| 
  [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
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits             | |||||||||||||||||||||||||||||||||||||
|  Copyright © 2001-2025 The PHP Group All rights reserved. | Last updated: Fri Oct 31 18:00:01 2025 UTC | 
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); ?>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");