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
Have you experienced this issue?
Rate the importance of this bug to you:

 [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

Add a Patch

Pull Requests

Add a Pull Request

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-2019 The PHP Group
All rights reserved.
Last updated: Thu Aug 22 11:01:26 2019 UTC