Req #71489 [Opn->Csd]: date_parse_from_format does not work with unix timestamp

From: Date: Thu, 23 Sep 2021 15:47:51 +0000
Subject: Req #71489 [Opn->Csd]: date_parse_from_format does not work with unix timestamp
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-236783@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=71489&edit=1 ID: 71489 Updated by: cmb@php.net Reported by: igorsantos07 at gmail dot com Summary: date_parse_from_format does not work with unix timestamp -Status: Open +Status: Closed Type: Feature/Change Request Package: Date/time related Operating System: Linux Mint 16 PHP Version: 5.6.17 -Assigned To: +Assigned To: cmb Block user comment: N Private report: N New Comment: > https://3v4l.org/5aeV3 This is implemented as of PHP 8.0.0. Previous Comments: ------------------------------------------------------------------------ [2016-02-01 20:13:53] requinix@php.net https://3v4l.org/5aeV3 It's always seemed to me that date_parse_from_format() is more about extracting values from a date string, not deriving a complete date from a given string. But I don't think there would be a problem with adding an exception where the entire date is populated if the input string has a timestamp. At the very least, year=1970 and such is a bit odd. ------------------------------------------------------------------------ [2016-02-01 14:24:33] igorsantos07 at gmail dot com Description: ------------ Using date_parse_from_format() with a Unix Timestamp yields no error, but does not yields valid results as well. It sets the date to 1970-1-1, instead of the correct date. Test script: --------------- $ php -a Interactive mode enabled php > $unix = date('U'); php > echo $unix; 1454336317 php > echo date('Y-m-d H:i:s', $unix); 2016-02-01 12:18:37 php > print_r(date_parse_from_format('U', $unix)); Array ( [year] => 1970 [month] => 1 [day] => 1 [hour] => 0 [minute] => 0 [second] => 0 [fraction] => 0 [warning_count] => 0 [warnings] => Array ( ) [error_count] => 0 [errors] => Array ( ) [is_localtime] => 1 [zone_type] => 1 [zone] => 0 [is_dst] => [relative] => Array ( [year] => 0 [month] => 0 [day] => 0 [hour] => 0 [minute] => 0 [second] => 1454336317 ) ) Expected result: ---------------- It should fill in the array with "2016-02-01 12:18:37" info. Actual result: -------------- The array is filled with "1970-01-01", without error messages. ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=71489&edit=1

« previous php.bugs (#236783) next »