|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #77788 date_add returns invalid time during DST transition
Submitted: 2019-03-24 09:31 UTC Modified: 2019-03-24 09:43 UTC
From: r dot schuil at gmail dot com Assigned:
Status: Open Package: Date/time related
PHP Version: 7.2.16 OS: Ubuntu
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please — but make sure to vote on the bug!
Your email address:
Solve the problem:
16 + 20 = ?
Subscribe to this entry?

 [2019-03-24 09:31 UTC] r dot schuil at gmail dot com
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:
$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


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2019-03-24 09:37 UTC]
-Status: Open +Status: Feedback
 [2019-03-24 09:37 UTC]
What does date_default_timezone_get() return?
 [2019-03-24 09:43 UTC] r dot schuil at gmail dot com
-Status: Feedback +Status: Open
 [2019-03-24 09:43 UTC] r dot schuil at gmail dot com
$ php -r 'echo date_default_timezone_get();
PHP Copyright © 2001-2019 The PHP Group
All rights reserved.
Last updated: Wed Sep 18 07:01:26 2019 UTC