|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2019-03-24 09:31 UTC] r dot schuil at gmail dot com
Description:
------------
When the addition to date/time causes it to be within the hour of DST transition, PHP returns an invalid date/time.
For example, 2019-01-31 02:00:12 plus two months returns 2019-03-31 02:00:12, which gets rejected by MySQL because the 3rd hour does not exist on this date. Instead, it should return 2019-03-31 03:00:12
Test script:
---------------
<?php
$date = date_create('2019-01-31 02:00:12');
date_add($date, date_interval_create_from_date_string('2 months'));
echo date_format($date, 'Y-m-d H:i:s');
?>
Expected result:
----------------
2019-03-31 03:00:12
Actual result:
--------------
2019-03-31 02:00:12
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Wed Nov 05 13:00:01 2025 UTC |
Thank you for this bug report. To properly diagnose the problem, we need a short but complete example script to be able to reproduce this bug ourselves. A proper reproducing script starts with <?php and ends with ?>, is max. 10-20 lines long and does not require any external resources such as databases, etc. If the script requires a database to demonstrate the issue, please make sure it creates all necessary tables, stored procedures etc. Please avoid embedding huge scripts into the report. I can't reproduce this with PHP 7.2.10, 7.2.35, 7.3.25, nor 8.0.3: 8.0.4-dev derick@gargleblaster:~/dev/php/php-src.git$ php -ddate.timezone=Europe/Berlin <?php $date = date_create('2019-01-31 02:00:12'); date_add($date, date_interval_create_from_date_string('2 months')); echo date_format($date, 'Y-m-d H:i:s'); ?> 2019-03-31 03:00:12