Calculating time difference between 2 dates in minutes(以分钟为单位计算两个日期之间的时间差)
问题描述
我的 MySQL 数据库中有一个时间戳字段,它映射到我的 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?
推荐答案
我想你可以使用 TIMESTAMPDIFF(unit,datetime_expr1,datetime_expr2) 类似
I think you could use TIMESTAMPDIFF(unit,datetime_expr1,datetime_expr2) something like
select * from MyTab T where
TIMESTAMPDIFF(MINUTE,T.runTime,NOW()) > 20
这篇关于以分钟为单位计算两个日期之间的时间差的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:以分钟为单位计算两个日期之间的时间差
- 如何使用 pip 安装 Python MySQLdb 模块? 2021-01-01
- 如何将 SonarQube 6.7 从 MySQL 迁移到 postgresql 2022-01-01
- 在SQL中,如何为每个组选择前2行 2021-01-01
- 导入具有可变标题的 Excel 文件 2021-01-01
- SQL 临时表问题 2022-01-01
- 更改自动增量起始编号? 2021-01-01
- 使用 Oracle PL/SQL developer 生成测试数据 2021-01-01
- 如何将 Byte[] 插入 SQL Server VARBINARY 列 2021-01-01
- 远程 mySQL 连接抛出“无法使用旧的不安全身份验证连接到 MySQL 4.1+"来自 XAMPP 的错误 2022-01-01
- 以一个值为轴心,但将一行上的数据按另一行分组? 2022-01-01
