如何在两个日期时间值之间的MYSQL中使用SQL减去并以分钟或秒为单位检索结果? [英] How do I subtract using SQL in MYSQL between two date time values and retrieve the result in minutes or second?

查看:144
本文介绍了如何在两个日期时间值之间的MYSQL中使用SQL减去并以分钟或秒为单位检索结果?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在MySQL中使用SQL在两个日期时间值之间减去,以便得到以分钟或秒为单位的间隔.有任何想法吗?我想运行一个SQL查询,该查询从数据库中检索已使用10分钟后的数据库的用户.

解决方案

有函数TIMEDIFF(expr1,expr2)返回expr1-expr2的值,以及TIME_TO_SEC(expr3)以秒表示expr1. >

请注意,expr1和expr2是日期时间值,而expr3仅是时间值.

检查此链接了解更多信息.

I want to subtract between two date time values using SQL in MySQL such that I get the interval in minutes or seconds. Any ideas? I want to run a SQL query that retrieves uses from a database who have logged in like 10 minutes from the time.

解决方案

There are functions TIMEDIFF(expr1,expr2), which returns the value of expr1-expr2, and TIME_TO_SEC(expr3), which expresses expr1 in seconds.

Note that expr1 and expr2 are datetime values, and expr3 is a time value only.

Check this link for more info.

这篇关于如何在两个日期时间值之间的MYSQL中使用SQL减去并以分钟或秒为单位检索结果?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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