|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #79716 Invalid date time created (with day "00")
Submitted: 2020-06-19 13:07 UTC Modified: 2020-06-19 14:14 UTC
From: a dot schilder at gmx dot de Assigned:
Status: Verified Package: Date/time related
PHP Version: 7.4.7 OS: Windows, Linux
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: a dot schilder at gmx dot de
New email:
PHP Version: OS:


 [2020-06-19 13:07 UTC] a dot schilder at gmx dot de
I'm doing some datetiem calculations. I have a start date time and calculate following dates based on recurrence rules. This means I add date intervals to the start date time value until a specific date time or number of results. Depending on the rule the date can be hundreds oy years in the future.

From time to time I got an error when trying to get the number of days in month of the resulting date time. The value I got was "0" (which isn't documented, because it shouldn't be possible). When I dum the object, the internal date time value is set to the invalid date "2770-01-00 15:00:00.000000".

I can't say how it came to the result, because there were too many date intervals added to the start date time, but it's easy to reproduced by creating a date time instance directly with this wrong time value.

Reproduced in the following PHP Versions:
7.2.2, 7.4.2, 7.4.7, 8.0.0-dev

Test script:
$datetime = new \DateTimeImmutable(
    '2770-01-00 15:00:00.000000',
    new \DateTimeZone('UTC')
\var_dump($datetime->format('j') === '0');

Expected result:
object(DateTimeImmutable)#3 (3) {
  string(26) "2769-12-31 15:00:00.000000"
  string(3) "UTC"

Actual result:
object(DateTimeImmutable)#3 (3) {
  string(26) "2770-01-00 15:00:00.000000"
  string(3) "UTC"


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2020-06-19 14:14 UTC]
-Status: Open +Status: Verified -Operating System: Windows 10 +Operating System: Windows, Linux
 [2020-06-19 14:14 UTC]
Confirmed: <>.  Doesn't seem to be Windows specific.
 [2020-06-20 10:12 UTC] a dot schilder at gmx dot de
In the meantime I could reproduce it using a date interval.

$datetime = new DateTimeImmutable('2768-12-31 15:00:00.000000', new \DateTimeZone('UTC'));
$datetime = $datetime->add(new \DateInterval('P1Y'));

object(DateTimeImmutable)#4 (3) {
  string(26) "2770-01-00 15:00:00.000000"
  string(3) "UTC"
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Thu Jan 21 09:01:23 2021 UTC