views:

92

answers:

3

I don't get it I want to calculate something I want to check if the time out of the database is before or after this time so I made 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 sais the date is somewhere in 2008 and now its 2009 the substract 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 get this am i just doing something wrong?

thanks Matthy

+7  A: 

try changing this $oldTime = mktime($aVraagCodeOp["Code_Expdate"]); to this $oldTime = strtotime($aVraagCodeOp["Code_Expdate"]);

Chris Gutierrez
+2  A: 

mktime() does not work that way.

You probably want strtotime()

timdev
+2  A: 

don't use mktime() in your example, use strtotime()

see: http://php.net/manual/en/function.strtotime.php

Lance Rushing