Bug #67354 [Opn->Nab]: Invalid year parse

From: Date: Wed, 28 May 2014 18:28:16 +0000
Subject: Bug #67354 [Opn->Nab]: Invalid year parse
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-185957@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=67354&edit=1 ID: 67354 Updated by: requinix@php.net Reported by: dr dot hab dot freek at gmail dot com Summary: Invalid year parse -Status: Open +Status: Not a bug Type: Bug -Package: *Data Exchange functions +Package: Date/time related Operating System: Debian PHP Version: 5.4.28 Block user comment: N Private report: N New Comment: > So - we see in manual strtotime() should working great with all formats from > http://www.php.net/manual/en/datetime.formats.php Not necessarily. It shows you all the formats that can be parsed but that doesn't mean each one by itself is suitable for use. #### matches against HHMM first. strtotime('1999') will give you the kind of result you're looking for. You want mktime(): date('Y-m-d H:i:s', mktime(0, 0, 0, 1, 1, 2008)) Previous Comments: ------------------------------------------------------------------------ [2014-05-28 18:14:50] dr dot hab dot freek at gmail dot com Description: ------------ So - we see in manual strtotime() should working great with all formats from http://www.php.net/manual/en/datetime.formats.php so if we run: date('Y-m-d H:i:s', strtotime('2008')); //return current date with the wrong time - 2014-05-28 20:08:00 So we can't use strtotime(date('Y')) so we should add month: strtotime(date('Y-m')) - then it works. Test script: --------------- date('Y-m-d H:i:s', strtotime('2008')); Expected result: ---------------- 2008-01-01 00:00:00 Actual result: -------------- 2014-05-28 20:08:00 //invalid date with modified time ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=67354&edit=1

« previous php.bugs (#185957) next »