dpqmu84646 2010-09-01 23:00
浏览 22
已采纳

MySQL / PHP - 时间过去了

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条回答 默认 最新

  • dongmin4990 2010-09-01 23:06
    关注

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

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 关于大棚监测的pcb板设计
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题