php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #75849 Different DateTime and strtotime with Relative Formats
Submitted: 2018-01-19 16:01 UTC Modified: 2018-01-19 16:07 UTC
From: wandersonwhcr at gmail dot com Assigned: daverandom (profile)
Status: Wont fix Package: Date/time related
PHP Version: 5.6.33 OS: Debian GNU/Linux 9.3 (stretch)
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: wandersonwhcr at gmail dot com
New email:
PHP Version: OS:

 

 [2018-01-19 16:01 UTC] wandersonwhcr at gmail dot com
Description:
------------
According to PHP Manual, DateTime class and strtotime functions use relative date and time formats.

http://php.net/manual/en/datetime.formats.relative.php

But using certain relative format in both classes, the result are not the same.

Only PHP 5.6 generates the problem. With PHP >=7.0, the outputs are the same. 

Test script:
---------------
<?php

echo date('c') . PHP_EOL; // Current Date and Time
$relative = 'first day of next month midnight -1 second';
echo date('c', (new DateTime($relative))->getTimestamp()) . PHP_EOL;
echo date('c', strtotime($relative)) . PHP_EOL;

?>

Expected result:
----------------
2018-01-19T13:51:58-02:00
2018-01-31T23:59:59-02:00
2018-01-31T23:59:59-02:00

Actual result:
--------------
2018-01-19T13:51:58-02:00
2018-01-01T23:59:59-02:00
2018-01-31T23:59:59-02:00

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2018-01-19 16:05 UTC] daverandom@php.net
-Status: Open +Status: Closed -Assigned To: +Assigned To: daverandom
 [2018-01-19 16:05 UTC] daverandom@php.net
PHP 5 is in security-only support http://php.net/supported-versions.php

This is not a security issue, and the behaviour has been fixed in currently supported PHP 7 versions. As such, the problem will not be addressed in older versions. Please migrate to PHP 7 as soon as possible.
 [2018-01-19 16:06 UTC] wandersonwhcr at gmail dot com
-Summary: Differente DateTime and strtotime with Relative Formats +Summary: Different DateTime and strtotime with Relative Formats -Status: Closed +Status: Open
 [2018-01-19 16:06 UTC] wandersonwhcr at gmail dot com
Summary Typo
 [2018-01-19 16:07 UTC] requinix@php.net
-Status: Open +Status: Wont fix
 [2018-01-19 16:07 UTC] wandersonwhcr at gmail dot com
You are right. Sorry.

Thank you :)
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Wed Jan 15 04:01:28 2025 UTC