|  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
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please — but make sure to vote on the bug!
Your email address:
Solve the problem:
41 - 17 = ?
Subscribe to this entry?

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

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:

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:

Actual result:


Add a Patch

Pull Requests

Add a Pull Request


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

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]
-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-2022 The PHP Group
All rights reserved.
Last updated: Fri May 20 18:05:43 2022 UTC