开发者

MySQL/PHP - Time Passed

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 th开发者_运维百科e 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);
}


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');

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜