|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2016-03-07 10:13 UTC] requinix@php.net
-Status: Open
+Status: Feedback
[2016-03-07 10:13 UTC] requinix@php.net
[2016-03-07 10:34 UTC] shadowspawnshadow at gmail dot com
-Status: Feedback
+Status: Open
[2016-03-07 10:34 UTC] shadowspawnshadow at gmail dot com
[2021-04-05 16:27 UTC] derick@php.net
-Package: Date/time related
+Package: Documentation problem
[2021-04-05 16:27 UTC] derick@php.net
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Thu Oct 30 16:00:01 2025 UTC |
Description: ------------ Date functions/methods like date_parse_from_format(), date_create_from_format()/DateTime::createFromFormat() ignore leading zeros in format and date string. So doe not make sense you use, for example, 'm' or 'n', both '01' and '1' passed without errors or warnings. Looks relevant to all versions from 5.2 to 5.6. Test script: --------------- <?php // date with leading zeros $d = '1990-01-02'; // format without leading zeros $f = 'Y-n-j'; print_r(date_parse_from_format($f, $d)); print_r(date_create_from_format($f, $d)); print_r(DateTime::getLastErrors()); echo '--------------------------'; // date without leading zeros $d = '1990-1-2'; // format with leading zeros $f = 'Y-m-d'; print_r(date_parse_from_format($f, $d)); print_r(date_create_from_format($f, $d)); print_r(DateTime::getLastErrors()); ?> Expected result: ---------------- Expect some warnings at least. Actual result: -------------- Array ( [year] => 1990 [month] => 1 [day] => 2 [hour] => [minute] => [second] => [fraction] => [warning_count] => 0 [warnings] => Array ( ) [error_count] => 0 [errors] => Array ( ) [is_localtime] => ) DateTime Object ( [date] => 1990-01-02 05:00:38.000000 [timezone_type] => 3 [timezone] => America/New_York ) Array ( [warning_count] => 0 [warnings] => Array ( ) [error_count] => 0 [errors] => Array ( ) ) -------------------------- Array ( [year] => 1990 [month] => 1 [day] => 2 [hour] => [minute] => [second] => [fraction] => [warning_count] => 0 [warnings] => Array ( ) [error_count] => 0 [errors] => Array ( ) [is_localtime] => ) DateTime Object ( [date] => 1990-01-02 05:00:38.000000 [timezone_type] => 3 [timezone] => America/New_York ) Array ( [warning_count] => 0 [warnings] => Array ( ) [error_count] => 0 [errors] => Array ( ) )