views:

30

answers:

1

How can I calculate the amount of 5 minuet periods passed with a datetime type?

is it possible?

//Update AP (+1 points every 5 mins)

//          PLAN OF ACTION (for ap update)!
// 1. check how long it has been since last update 
// 2. calculate how many 5 min periods has passed 
// 3. update $ap accordinly 
if ($last_ap_update != "0000-00-00 00:00:00"){ //Make sure last_ap_update has a value


}
else{ //If the last update is NULL, It must be players first page load. So set datetime equal to NOW
    $query = "UPDATE `stats` SET `last_ap_update` = NOW() WHERE `member_id` = {$_SESSION['SESS_MEMBER_ID']}"; 
    $queryresult = @mysql_query($query);
}
+1  A: 

Subtract past unix timestamp from current unix timestamp then divide result by 300 (60*5).

You can convert a MySQL datetime into a unix timestamp by either:

  • Using the SQL UNIX_TIMESTAMP function, i.e., SELECT UNIX_TIMESTAMP(last_ap_update)

  • Pass a datetime string into PHP's strtotime, i.e, strtotime('2009-10-31 12:59:59');

webbiedave
could you post the code for that, im kinda new to php.... :]