|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2004-03-18 11:02 UTC] kingoleg at mail dot ru
Description:
------------
strtotime() do not correct work with MySQL datetime(14).
Founded in Smarty shared.make_timestamp.php:
function smarty_make_timestamp($string)
{
//Skiped
$time = strtotime($string);
//For date before 20040318000000 return -1
//After 20040318100000 return timestamp
if (is_numeric($time) && $time != -1)
return $time;
// is mysql timestamp format of YYYYMMDDHHMMSS?
if (preg_match('/^\d{14}$/', $string)) {
//Skiped
}
}
Reproduce code:
---------------
Type this code:
<?php
$t = strtotime('20040318000000');
echo $t;
echo "<br>"
$t = strtotime('20040318100000');
echo $t;
?>
Expected result:
----------------
-1
149979600
Actual result:
--------------
-1
-1
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Fri Nov 28 21:00:01 2025 UTC |
"Borders" of this bug: '20040318094229' '20040318094230' Manual: Because strtotime() behaves according to GNU date syntax, have a look at the GNU manual page titled Date Input Formats. Described there is valid syntax for the time parameter. So, neither '20040318094229' nor '20040318094230' are both not valid syntax for the time parameter. But... Test result: 20040318094231 -1 79200 165600 Test source: <?php $date = '20040317'; $h = '00'; $i = '00'; $s = '00'; $t = -1; while($t == -1) { $t = strtotime($date.$h.$i.$s); $s++; if (strlen($s) == 1) { $s = '0'.$s; } if ($s == 60) { $s = 0; $i++; } if (strlen($i) == 1) { $i = '0'.$i; } if ($i == 60) { $i = 0; $h++; } if (strlen($h) == 1) { $h = '0'.$h; } if ($h == 24) { $h = 0; $date++; } if ($date == 20040319) { break; } } echo $date.$h.$i.$s; echo '<br>'; echo '<br>'; echo '<br>'; echo '<br>'; echo strtotime('20040318094229'); echo '<br>'; echo strtotime('20040318094230'); echo '<br>'; echo strtotime('20040318094231'); ?> P.S. Sorry, I wrote "Actual result" as "Expected result". P.P.S. Russian description of this bug is here http://rsdn.ru/Forum/Message.aspx?mid=573729&only=1