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);
}
0

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.