PHP timestamp time function: 2008 is larger than 2009?
I don't get it. I want to check if the time out of the database is before or after the current time, so I wrote this:
$qVraagCodeOp = "SELECT * FROM `code` WHERE `Code_Code` = '$value'";
$rVraagCodeOp = mysql_query($qVraagCodeOp);
$aVraagCodeOp = mysql_fetch_assoc($rVraagCodeOp);
$oldTime = mktime($aVraagCodeOp["Code_Expdate"]);
$nowTime = time();
echo "databaseTime = $aVraagCodeOp[Code_Expdate] <br />";
echo "mktime =" . $oldTime . "<br />";
echo "timestamp now = $nowTime <br />";
echo 'today: '. date('Y-m-d', $nowTime ) ."<br />";
echo "new minus old =" . ($nowTime - $oldTime);
Because the database says the date is somewhere in 2008 and the current date is in 2009, the subtraction result should be positive. However, this is the output:
开发者_开发百科databaseTime = 2008-12-01
mktime =1263136596
timestamp now = 1255907796
today: 2009-10-19
new minus old =-7228800
Does anyone understand this? Am I just doing something wrong?
try changing this $oldTime = mktime($aVraagCodeOp["Code_Expdate"]);
to this $oldTime = strtotime($aVraagCodeOp["Code_Expdate"]);
mktime() does not work that way.
You probably want strtotime()
don't use mktime() in your example, use strtotime()
see: http://php.net/manual/en/function.strtotime.php
精彩评论