|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2006-02-02 20:42 UTC] tim at komta dot com
Description:
------------
Previously valid strtotime() attempts no longer parse to a time. This worked prior to PHP 5.1, I believe.
Reproduce code:
---------------
<?php
echo strtotime('02/02/2006 11');
?>
Expected result:
----------------
1138896000 (with the server timezone set to EST)
Actual result:
--------------
FALSE
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sun Oct 26 17:00:01 2025 UTC |
strtotime('11') exhibits the same behavior change - seems that strtotime can no longer handle only 2 digits for a time.--WORKAROUND-- For anyone wishing to replicate the prior behavior, I wrote this regex to use with preg_replace() immediately prior to calling the strtotime() on your value. $value = preg_replace('#(.*)(^|\s)([0-9]{1,2})$#', '$1$2${3}00', $value); $timestamp = strtotime($value); This function call adds two zeroes to a 1 or two digit number either on it's own (11) or trailing a whitespace character (2/13/06 11). It will not match a two-digit year (ie, in 2/13/06, it will not match "06")