Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我目前有一个数据库,其中包含last_login数据last_logout类型设置为datetime. 当用户登录和退出系统时,这两列中的时间都会更新。
last_login
last_logout
datetime
我现在想创建一个通知,通知用户他们以前何时登录系统。我想以小时为单位显示答案,例如(23 小时前或 128 小时前)。
我只是不知道如何在 PHP 中使用这些列中的值执行计算。请帮忙。
如果这个问题难以理解,我深表歉意。
SELECT (TIME_TO_SEC(TIMEDIFF(LOGOUT_COLUMN, LOGIN_COLUMN)) / 3600) AS TimeDiff
应该做的伎俩,将在几秒钟内返回差异,然后在 PHP 端你可以在几分钟或几小时内转换它。
在mysql中做
Select TimeStampDiff(HOUR,LastLoginTime,Now()) From MyLoginTable
例如