Professional Web Applications Themes

#39560 [NEW]: Inconsistent behaviour of strtotime when days > days in month - PHP Bugs

From: php at colin dot guthr dot ie Operating system: Linux PHP version: 5.2.0 PHP Bug Type: Date/time related Bug description: Inconsistent behaviour of strtotime when days > days in month Description: ------------ If you give a date to strtotime that is beyond the end of a given month it sometimes calculates the date correctly (IMO) as the first day of the next month, but this does not happen in months with 31 days. e.g. strtotime('2006-11-31') will correctly create a date of 2006-12-01, but strtotime('2006-11-32') will not create a date of 2007-01-01 as expected. This is the case for all ...

  1. #1

    Default #39560 [NEW]: Inconsistent behaviour of strtotime when days > days in month

    From: php at colin dot guthr dot ie
    Operating system: Linux
    PHP version: 5.2.0
    PHP Bug Type: Date/time related
    Bug description: Inconsistent behaviour of strtotime when days > days in month

    Description:
    ------------
    If you give a date to strtotime that is beyond the end of a given month it
    sometimes calculates the date correctly (IMO) as the first day of the next
    month, but this does not happen in months with 31 days.

    e.g. strtotime('2006-11-31') will correctly create a date of 2006-12-01,
    but strtotime('2006-11-32') will not create a date of 2007-01-01 as
    expected. This is the case for all months that have 30 days (and I presume
    february too). Putting in 31 as the number will overflow to the next month,
    but putting in 32 in any month will not overflow to the 1st or 2nd day of
    the next month as appropriate (usual exceptions for February apply!)

    See example code below for examples.

    Reproduce code:
    ---------------
    <table><tr><th>Date</th><th>Expected Result</th><th>Actual
    Result</th><th>Pass/Fail?</th></tr><?php
    $arr_dates = array('2006-11-30 + 1 day' => '2006-12-01',
    '2006-11-30 + 2 days' => '2006-12-02',
    '2006-12-31 + 1 day' => '2007-01-01',
    '2006-06-31' => '2006-07-01',
    '2006-07-32' => '2006-08-01',
    '2006-11-31' => '2006-12-01',
    '2006-11-32' => '2006-12-02',
    '2006-12-32' => '2007-01-01');
    foreach ($arr_dates as $source => $expected)
    {
    $result = date('Y-m-d', strtotime($source));
    echo '<tr class="'.($result == $expected ? 'pass' : 'fail').'">';
    echo '<td>'.$source.'</td>';
    echo '<td>'.$expected.'</td>';
    echo '<td>'.$result.'</td>';
    echo '<td>'.($result == $expected ? 'Pass' : 'Fail').'</td>';
    echo '</tr>';
    }
    ?>
    </table>

    Expected result:
    ----------------
    Results are contained above if you run it.

    Actual result:
    --------------
    Actual results are contained above if you run it.

    --
    Edit bug report at [url]http://bugs.php.net/?id=39560&edit=1[/url]
    --
    Try a CVS snapshot (PHP 4.4): [url]http://bugs.php.net/fix.php?id=39560&r=trysnapshot44[/url]
    Try a CVS snapshot (PHP 5.2): [url]http://bugs.php.net/fix.php?id=39560&r=trysnapshot52[/url]
    Try a CVS snapshot (PHP 6.0): [url]http://bugs.php.net/fix.php?id=39560&r=trysnapshot60[/url]
    Fixed in CVS: [url]http://bugs.php.net/fix.php?id=39560&r=fixedcvs[/url]
    Fixed in release: [url]http://bugs.php.net/fix.php?id=39560&r=alreadyfixed[/url]
    Need backtrace: [url]http://bugs.php.net/fix.php?id=39560&r=needtrace[/url]
    Need Reproduce Script: [url]http://bugs.php.net/fix.php?id=39560&r=needscript[/url]
    Try newer version: [url]http://bugs.php.net/fix.php?id=39560&r=oldversion[/url]
    Not developer issue: [url]http://bugs.php.net/fix.php?id=39560&r=support[/url]
    Expected behavior: [url]http://bugs.php.net/fix.php?id=39560&r=notwrong[/url]
    Not enough info: [url]http://bugs.php.net/fix.php?id=39560&r=notenoughinfo[/url]
    Submitted twice: [url]http://bugs.php.net/fix.php?id=39560&r=submittedtwice[/url]
    register_globals: [url]http://bugs.php.net/fix.php?id=39560&r=globals[/url]
    PHP 3 support discontinued: [url]http://bugs.php.net/fix.php?id=39560&r=php3[/url]
    Daylight Savings: [url]http://bugs.php.net/fix.php?id=39560&r=dst[/url]
    IIS Stability: [url]http://bugs.php.net/fix.php?id=39560&r=isapi[/url]
    Install GNU Sed: [url]http://bugs.php.net/fix.php?id=39560&r=gnused[/url]
    Floating point limitations: [url]http://bugs.php.net/fix.php?id=39560&r=float[/url]
    No Zend Extensions: [url]http://bugs.php.net/fix.php?id=39560&r=nozend[/url]
    MySQL Configuration Error: [url]http://bugs.php.net/fix.php?id=39560&r=mysqlcfg[/url]
    php at colin dot guthr dot ie Guest

  2. #2

    Default #39560 [Opn->Bgs]: Inconsistent behaviour of strtotime when days > days in month

    ID: 39560
    Updated by: [email]derickphp.net[/email]
    Reported By: php at colin dot guthr dot ie
    -Status: Open
    +Status: Bogus
    Bug Type: Date/time related
    Operating System: Linux
    PHP Version: 5.2.0
    New Comment:

    Thank you for taking the time to write to us, but this is not
    a bug. Please double-check the doentation available at
    [url]http://www.php.net/manual/[/url] and the instructions on how to report
    a bug at [url]http://bugs.php.net/how-to-report.php[/url]

    The pr rejects day numbers that can never exist (such as the 32rd).
    However, in case you use a day number that is legal (01-31) it is used
    correctly and the month will "overflow".


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

    [2006-11-20 17:03:48] php at colin dot guthr dot ie

    Description:
    ------------
    If you give a date to strtotime that is beyond the end of a given month
    it sometimes calculates the date correctly (IMO) as the first day of the
    next month, but this does not happen in months with 31 days.

    e.g. strtotime('2006-11-31') will correctly create a date of
    2006-12-01, but strtotime('2006-11-32') will not create a date of
    2007-01-01 as expected. This is the case for all months that have 30
    days (and I presume february too). Putting in 31 as the number will
    overflow to the next month, but putting in 32 in any month will not
    overflow to the 1st or 2nd day of the next month as appropriate (usual
    exceptions for February apply!)

    See example code below for examples.

    Reproduce code:
    ---------------
    <table><tr><th>Date</th><th>Expected Result</th><th>Actual
    Result</th><th>Pass/Fail?</th></tr><?php
    $arr_dates = array('2006-11-30 + 1 day' => '2006-12-01',
    '2006-11-30 + 2 days' => '2006-12-02',
    '2006-12-31 + 1 day' => '2007-01-01',
    '2006-06-31' => '2006-07-01',
    '2006-07-32' => '2006-08-01',
    '2006-11-31' => '2006-12-01',
    '2006-11-32' => '2006-12-02',
    '2006-12-32' => '2007-01-01');
    foreach ($arr_dates as $source => $expected)
    {
    $result = date('Y-m-d', strtotime($source));
    echo '<tr class="'.($result == $expected ? 'pass' : 'fail').'">';
    echo '<td>'.$source.'</td>';
    echo '<td>'.$expected.'</td>';
    echo '<td>'.$result.'</td>';
    echo '<td>'.($result == $expected ? 'Pass' : 'Fail').'</td>';
    echo '</tr>';
    }
    ?>
    </table>

    Expected result:
    ----------------
    Results are contained above if you run it.

    Actual result:
    --------------
    Actual results are contained above if you run it.


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


    --
    Edit this bug report at [url]http://bugs.php.net/?id=39560&edit=1[/url]
    derick@php.net Guest

Similar Threads

  1. Replies: 2
    Last Post: November 4th, 09:50 PM
  2. #25937 [NEW]: strtotime weirdness with days of week
    By six at t0x dot net in forum PHP Development
    Replies: 0
    Last Post: October 21st, 03:45 PM
  3. Display month and days with results
    By Andy Hassall in forum PHP Development
    Replies: 0
    Last Post: August 17th, 05:10 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139