如何计算MySQL时间戳和PHP当前时间之间的差异

|| 我正在尝试计算从MySQL数据库检索到的时间戳与当前时间之间的差异。 感谢帮助。     
已邀请:
如@RemoteSojourner所述,我以UNIX时间戳格式获取当前时间(以秒为单位返回时间),从数据库(使用ORM)获取时间戳,并将其也转换为UNIX timstamp,然后减去两个时间戳。 。
            $current_time = strtotime(\"now\");
            $last_access_time = strtotime($this->last_access);
            $inactivity_duration = $current_time - $last_access_time;
    
此示例使现在和一个小时前有所不同。 选择timediff(now(),now()-间隔1小时)     
您可以使用strtotime函数将MySQL时间戳解析为Unix时间戳,可以在PHP date函数中进一步解析或格式化该时间戳。     
这样从mysql检索日期时间
SELECT UNIX_TIMESTAMP(`time_col`) FROM `tablename`...
并将其与
time()
进行比较     

要回复问题请先登录注册