php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #70694 When using the date function, I have a problem
Submitted: 2015-10-12 08:59 UTC Modified: 2015-10-12 09:21 UTC
From: bear dot gan at qq dot com Assigned:
Status: Not a bug Package: Calendar related
PHP Version: 5.4Git-2015-10-12 (Git) OS: ubuntu 14 ,windows
Private report: No CVE-ID: None
 [2015-10-12 08:59 UTC] bear dot gan at qq dot com
Description:
------------
When using the date function, I have a problem, set up a date 2099/3/31, the results in the conversion of PHP

$t = '2099-3-31 0:0:0';
$time = strtotime($t);
echo $time.': '.date('Y-m-d H:i:s', $time).'<br>';

The result of echo is 00:00:00 1970-01-01

Test script:
---------------
$t = '2099-3-31 0:0:0';
$time = strtotime($t);
echo $time.': '.date('Y-m-d H:i:s', $time).'<br>';

Expected result:
----------------
[echo]The result of echo is  1970-01-01 00:00:00

Actual result:
--------------
2099-3-31 0:0:0

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2015-10-12 09:00 UTC] stas@php.net
-Package: PHP Language Specification +Package: Calendar related
 [2015-10-12 09:21 UTC] derick@php.net
-Status: Open +Status: Not a bug
 [2015-10-12 09:21 UTC] derick@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

You are on windows, which only supports 32 bit integers. The timestamp for "2099-3-31" would fall outside of the 32-bit range, which runs out somewhere in 2038. What you want to do is:

$dt = new DateTime("2099-3-31 0:0:0");
echo $dt->format("Y-m-d H:i:s");
 
PHP Copyright © 2001-2020 The PHP Group
All rights reserved.
Last updated: Wed Sep 23 04:01:25 2020 UTC