计算2个日期之间的时差(以分钟为单位) [英] Calculating time difference between 2 dates in minutes

查看:151
本文介绍了计算2个日期之间的时差(以分钟为单位)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的MySQL数据库中有一个时间字段Timestamp,它映射到bean中的DATE数据类型.现在,我想要一个查询,通过该查询可以获取数据库中的所有记录,这些记录的当前时间戳与存储在数据库中的时间戳之间的差异大于20分钟.

I have a field of time Timestamp in my MySQL database which is mapped to a DATE datatype in my bean. Now I want a query by which I can fetch all records in the database for which the difference between the current timestamp and the one stored in the database is > 20 minutes.

我该怎么办?

我想要的是:

SELECT * FROM MyTab T WHERE T.runTime - now > 20 minutes

是否有用于此的MySQL函数,或以任何方式在SQL中做到这一点?

Are there any MySQL functions for this, or any way to do this in SQL?

推荐答案

我认为您可以使用

I think you could use TIMESTAMPDIFF(unit,datetime_expr1,datetime_expr2) something like

select * from MyTab T where
TIMESTAMPDIFF(MINUTE,T.runTime,NOW()) > 20

这篇关于计算2个日期之间的时差(以分钟为单位)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆