I am getting a continues mktime error in my website.
Main mktime code from the functions.php is below:
function mkprettytime($s) {
if ($s < 0)
$s = 0;
$t = array();
$t["day"] = floor($s / 86400);
$s -= $t["day"] * 86400;
$t["hour"] = floor($s / 3600);
$s -= $t["hour"] * 3600;
$t["min"] = floor($s / 60);
$s -= $t["min"] * 60;
$t["sec"] = $s;
if ($t["day"])
return $t["day"] . "d " . sprintf("%02d:%02d:%02d", $t["hour"], $t["min"], $t["sec"]);
if ($t["hour"])
return sprintf("%d:%02d:%02d", $t["hour"], $t["min"], $t["sec"]);
return sprintf("%d:%02d", $t["min"], $t["sec"]);
}
function sql_timestamp_to_unix_timestamp($s){
return mktime(substr($s, 11, 2), substr($s, 14, 2), substr($s, 17, 2), substr($s, 5, 2), substr($s, 8, 2), substr($s, 0, 4));
}
And the error is:
[12-Feb-2013 11:06:36] PHP Warning: mktime() expects parameter 4 to be long, string given in /home/myweb/public_html/bgcode/functions.php on line 543
And the 543 line is (from the above line/script)
return mktime(substr($s, 11, 2), substr($s, 14, 2), substr($s, 17, 2), substr($s, 5, 2), substr($s, 8, 2), substr($s, 0, 4));
Since all the values you are passing are strings, and the fourth one needs to be a number, you need to count to the fourth parameter and make sure that's a number instead. If your substr's are done correctly (I didn't check) it will be a simple matter to convert that value to a number before passing it. First thing to do is double-check that what you pass as parameter 4 is what you think it is. Then read up on intval()
: http://php.net/manual/en/function.intval.php
Edit to add: After another minute of pondering, I question that you would ever need a function like that (if you're using MySQL, see UNIX_TIMESTAMP()), and even if you did, strtotime() probably will do the heavy lifting for you.
Actually, I think you're looking for the strtotime function, not mktime:
http://www.php.net/manual/en/function.strtotime.php
Then you can just call strtotime instead of making your own sql_timestamp_to_unix_timestamp function, unless you want it to handle invalid values differently than strtotime does itself.