Bug #75849 [Com]: Different DateTime and strtotime with Relative Formats

From: Date: Fri, 19 Jan 2018 16:07:37 +0000
Subject: Bug #75849 [Com]: Different DateTime and strtotime with Relative Formats
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-213625@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=75849&edit=1 ID: 75849 Comment by: wandersonwhcr at gmail dot com Reported by: wandersonwhcr at gmail dot com Summary: Different DateTime and strtotime with Relative Formats Status: Wont fix Type: Bug Package: Date/time related Operating System: Debian GNU/Linux 9.3 (stretch) PHP Version: 5.6.33 Assigned To: daverandom Block user comment: N Private report: N New Comment: You are right. Sorry. Thank you :) Previous Comments: ------------------------------------------------------------------------ [2018-01-19 16:06:25] wandersonwhcr at gmail dot com Summary Typo ------------------------------------------------------------------------ [2018-01-19 16:05:52] 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:01:27] 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 ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=75849&edit=1

« previous php.bugs (#213625) next »