|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #78496 date_create rolls a day back on year 0000 timestamp
Submitted: 2019-09-05 15:56 UTC Modified: 2020-01-20 17:14 UTC
From: dzuczek at dlc-solutions dot com Assigned: derick (profile)
Status: Assigned Package: Date/time related
PHP Version: 7.2.22 OS: 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: dzuczek at dlc-solutions dot com
New email:
PHP Version: OS:


 [2019-09-05 15:56 UTC] dzuczek at dlc-solutions dot com
date_create seems to roll back a day when given a timestamp in the year 0000

this worked as expected in PHP 7.1, does not work in PHP 7.2 or greater

Test script:
Not working (year 0000):
Working (year 0001):

$timestamp = strtotime('0000-02-20 00:00:00 UTC'); // has issues
$timestamp2 = strtotime('0001-02-20 00:00:00 UTC'); // this is okay

// this has issues
print $timestamp . "\n";
$date_time = date_create('@' . $timestamp);

// this is fine
print $timestamp2 . "\n";
$date_time2 = date_create('@' . $timestamp2);

Expected result:
Using 0000-02-20 00:00:00 UTC

Expected (PHP 7.1)

DateTime Object
    [date] => 0000-02-20 00:00:00.000000
    [timezone_type] => 1
    [timezone] => +00:00

Actual result:
Using 0000-02-20 00:00:00 UTC

Actual (PHP 7.2+)

DateTime Object
    [date] => 0000-02-19 00:00:00.000000
    [timezone_type] => 1
    [timezone] => +00:00

The resulting date has been rolled back a day.


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2019-09-05 16:02 UTC] dzuczek at dlc-solutions dot co
Passing a date instead of seconds does work:


$date_time = date_create('0000-02-20 00:00:00 UTC');

$date_time = date_create('0001-02-20 00:00:00 UTC');
 [2019-09-05 16:24 UTC] dzuczek at dlc-solutions dot com
More tests, looks like it's just February dates...

0000-01-20 00:00:00 UTC (works)
0000-02-20 00:00:00 UTC (fails)
0000-03-20 00:00:00 UTC (works)
 [2019-09-05 16:47 UTC]
Well, actually there is no year 0 in the Gregorian calendar.
 [2019-09-05 23:41 UTC] alexanderpas at gmail dot com
ISO 8601 defines the year zero as the year 1 BC in the Gregorian calendar.

The last few days in January are also affected.
 [2020-01-20 17:14 UTC]
-Assigned To: +Assigned To: derick
 [2020-04-17 06:31 UTC] alexanderpas at gmail dot com
This also affects getting a timestamp out of a DateTime object created with a timestamp. (Where the output should always be the same as the input)

See which has some additional testcases.
 [2021-02-08 05:01 UTC] justinpor119 at gmail dot com
The date was parsed in UTC (GMT) because you provided a date-only string without any time zone indicator. If you had given a date/time string w/o an indicator instead (new Date("2011-09-24T00:00:00")), it would have been parsed in your local timezone.
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Thu Aug 05 22:01:24 2021 UTC