php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #77745 Unexpected result DateTime::createFromFormat
Submitted: 2019-03-14 20:51 UTC Modified: 2019-03-14 20:57 UTC
From: dnkonev at yandex dot ru Assigned:
Status: Not a bug Package: Date/time related
PHP Version: 7.1.27 OS: Ubuntu 18.04.1 LTS
Private report: No CVE-ID: None
 [2019-03-14 20:51 UTC] 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;


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2019-03-14 20:57 UTC] requinix@php.net
-Status: Open +Status: Not a bug
 [2019-03-14 20:57 UTC] requinix@php.net
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.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Apr 25 19:01:33 2024 UTC