I have a code but can’t find where is an error. I have upcoming event and current time. If I convert my event to the timestamp it’s less then current timestamp. May be you can help me.
My code below:
<?php
date_default_timezone_set('Etc/GMT');
$upcoming = "2012.09.05 23:50";
$current = time();
echo "Upcoming: " . $upcoming . " | Timestamp:" . mktime(23, 50, 0, 09, 05, intval(date("Y")));
echo "<br>Current: " . time();
echo "<br>Current SIM: " . mktime(date("H"), date("i"), date("s"), date("m"), date("d"), date("Y"));
?>
Will output:
Upcoming: 2012.09.05 23:50 | Timestamp:1323129000
Current: 1346855221
Current SIM: 1346855220
Where Current > Upcoming timestamp. (???)
Thanks!
Because you have 09 (with a preceding 0) this number is interpreted as an octal number, and so it’s converted to 0.
Use:
mktime(23, 50, 0, 9, 5, intval(date("Y")));You can explore this “feature” a bit;
EDIT;
date('n');returns the month without leading zeros. Anddate('j');anddate('G');return the day and hour without leading zeros. So you can changemktime(date("H"), date("i"), date("s"), date("m"), date("d"), date("Y"));tomktime(date("G"), date("i"), date("s"), date("n"), date("j"), date("Y"));There’s no way to get the number of minutes and seconds without leading zeros with
date()so maybe you need to find another function for that.EDIT:
To convert
2012.09.05 23:50to a timestamp you can change the.to/and feed it tostrtotime():