Bug #77745 [Opn->Nab]: Unexpected result DateTime::createFromFormat

From: Date: Thu, 14 Mar 2019 20:57:41 +0000
Subject: Bug #77745 [Opn->Nab]: Unexpected result DateTime::createFromFormat
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-219969@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=77745&edit=1 ID: 77745 Updated by: requinix@php.net Reported by: dnkonev at yandex dot ru Summary: Unexpected result DateTime::createFromFormat -Status: Open +Status: Not a bug Type: Bug Package: Date/time related Operating System: Ubuntu 18.04.1 LTS PHP Version: 7.1.27 Block user comment: N Private report: N New Comment: Thank you for taking the time to write to us, but this is not a bug. Please double-check the documentation available at http://www.php.net/manual/ and the instructions on how to report a bug at http://bugs.php.net/how-to-report.php 'Y' expects the "full numeric representation of a year", which is probably but not necessarily going to be four digits. If you give it 29 it will assume 0029, and if you give it 10 it will assume 0010. If you have two digits and want a year between 1970-2069 then use 'y' instead. Previous Comments: ------------------------------------------------------------------------ [2019-03-14 20:51:47] dnkonev at yandex dot ru Description: ------------ --- From manual page: https://php.net/datetime.createfromformat --- PHP VER: PHP 7.1.26-1+ubuntu18.04.1+deb.sury.org+1 (cli) (built: Jan 11 2019 14:13:49) ( NTS ) Copyright (c) 1997-2018 The PHP Group Zend Engine v3.1.0, Copyright (c) 1998-2018 Zend Technologies with Zend OPcache v7.1.26-1+ubuntu18.04.1+deb.sury.org+1, Copyright (c) 1999-2018, by Zend Technologies with Xdebug v2.6.0, Copyright (c) 2002-2018, by Derick Rethans When I use "Y" as the first argument and pass the value of two numbers as the second argument, function executed without errors and returns a DateTime object. Year in this DateTime object takes the value "00 + two numbers that I have passed" Test script: --------------- <?php $a = \DateTime::createFromFormat('m/d/Y', '12/31/29'); echo $a->format('Y-m-d') . PHP_EOL; $a = \DateTime::createFromFormat('Y', '10'); echo $a->format('Y-m-d') . PHP_EOL; ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=77745&edit=1

« previous php.bugs (#219969) next »