CodeIgniter Forums
php date mktime related question - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: php date mktime related question (/showthread.php?tid=13012)



php date mktime related question - El Forum - 11-07-2008

[eluser]quasiperfect[/eluser]
hi

can anyone spot the bug in this code because i'm going nuts.
thanks a lot

Code:
function to_timestamp($str) {
$segmente = explode(" ",$str);
$data = explode("-",$segmente[0]);
$timp = explode(":",$segmente[1]);
$timestamp = mktime($timp[0], $timp[1], $timp[2], $data[1], $data[2], $data[0]);
return $timestamp;
}
$str="2008-11-07 10:02:00";
$timestamp = to_timestamp($str);
echo 'this script should return '.$str.' insted is returning '.date("Y-m-d H:m:s",$timestamp).'<br />';

for
Code:
$str="2008-10-07 13:02:40"
this script should return 2008-10-07 13:02:40 insted is returning 2008-10-07 13:10:40

after some random testing i observed that the month is passed to the minutes
change the month to any month and see the result at minutes


php date mktime related question - El Forum - 11-07-2008

[eluser]Pascal Kriete[/eluser]
Minute is i, not m Wink .

Also, strtotime will do the job natively.


php date mktime related question - El Forum - 11-07-2008

[eluser]quasiperfect[/eluser]
damn i'm a moron ty inparo