ID:               50249
 Updated by:       der...@php.net
 Reported By:      jennifer dot kimball at nrc dot ca
-Status:           Open
+Status:           Assigned
 Bug Type:         Date/time related
 Operating System: Solaris 10
 PHP Version:      5.3.1
-Assigned To:      
+Assigned To:      derick
 New Comment:

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!


Previous Comments:
------------------------------------------------------------------------

[2009-11-23 13:05:24] sjo...@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-20 18:18:22] 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


------------------------------------------------------------------------


-- 
Edit this bug report at http://bugs.php.net/?id=50249&edit=1

Reply via email to