php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #27634 strtotime(%MySQL datetime(14)%)
Submitted: 2004-03-18 11:02 UTC Modified: 2005-09-25 12:56 UTC
Votes:2
Avg. Score:3.0 ± 1.0
Reproduced:2 of 2 (100.0%)
Same Version:2 (100.0%)
Same OS:2 (100.0%)
From: kingoleg at mail dot ru Assigned:
Status: Closed Package: Feature/Change Request
PHP Version: 4.3.4, 5CVS OS: All
Private report: No CVE-ID: None
 [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

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-03-18 11:12 UTC] derick@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

strtotime doesn\'t support it.
 [2004-03-24 04:28 UTC] kingoleg at corason dot ua
"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
 [2004-03-24 08:55 UTC] kingoleg at mail dot ru
As I know, in php 4 and php 5 strtotime do support it. It's wrong.
 [2005-09-25 12:56 UTC] nlopess@php.net
14-chars mysql timestamps work since PHP 5.1.0.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Wed Sep 18 22:01:26 2024 UTC