在 MySQL 中减去两个具有时间数据类型的字段 [英] Subtract two field w/ time data type in MySQL
本文介绍了在 MySQL 中减去两个具有时间数据类型的字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用 PHP 在我的 mysql 表中插入和更新记录.如果两个字段 w/time 数据类型的差异超过 15 分钟,我想将 is_logout 字段更新为 1.
I am using PHP to insert and update record on my mysql table. I want to update the is_logout field to 1 if the difference of two field w/ time data type is more than 15 minutes.
我有 time_start 和 time_latest.
I have time_start and time_latest.
查询将如下所示:
UPDATE table set is_logout = 1 WHERE (time_latest - time_start) > 15
如何做到这一点?
推荐答案
使用以下查询:
UPDATE table set is_logout = 1 WHERE (NOW() - time_start) >15
NOW()
会给你当前时间.我相信您的数据库中有 time_start
.
NOW()
will give you current time. I believe you have time_start
in your database.
这篇关于在 MySQL 中减去两个具有时间数据类型的字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文