php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #67354 Invalid year parse
Submitted: 2014-05-28 18:14 UTC Modified: 2014-05-28 18:31 UTC
From: dr dot hab dot freek at gmail dot com Assigned:
Status: Not a bug Package: Date/time related
PHP Version: 5.4.28 OS: Debian
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: dr dot hab dot freek at gmail dot com
New email:
PHP Version: OS:

 

 [2014-05-28 18:14 UTC] 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

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2014-05-28 18:28 UTC] requinix@php.net
-Status: Open +Status: Not a bug -Package: *Data Exchange functions +Package: Date/time related
 [2014-05-28 18:28 UTC] requinix@php.net
> 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))
 [2014-05-28 18:31 UTC] requinix@php.net
> strtotime('1999') will give you the kind of result you're looking for.
By that I mean it gives you a timestamp from that year. It won't be for midnight on January 1st but instead copies the current time's components.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Sep 28 01:01:27 2024 UTC