简体   繁体   English

timediff大于2分钟

[英]timediff is greater than 2 minutes

I am trying to write a query where I can eliminate a timediff of less than 2 minutes. 我正在尝试编写一个查询,我可以消除不到2分钟的timediff。 I have tried variations on the following which returns no results 我尝试了以下的变体,没有返回任何结果

 timediff(sessions.producer_on,sessions.producer_off)>'00:02:00'

the timediff without the > works fine and returns all results - I am having difficulty with the >00:02:00 condition. timediff没有>工作正常并返回所有结果 - 我遇到了> 00:02:00条件的困难。 Can anyone help - many thanks 任何人都可以帮忙 - 非常感谢

You need to extract the minute from the time then compare it. 您需要从时间中提取分钟然后进行比较。

minute(timediff(sessions.producer_on,sessions.producer_off)) > 2 AND 
hour(timediff(sessions.producer_on,sessions.producer_off)) = 0

Also it may be necessary to make sure that the hour is 0 since only when the hour is zero does the minute actually matter. 此外,可能需要确保小时为0,因为只有当小时为零时,分钟才真正重要。

This is probably the "old way" but it eliminates the need to check hours, days, etc. 这可能是“旧方法”,但它不需要检查小时,天等。

UNIX_TIMESTAMP(fieldOne) - UNIX_TIMESTAMP(fieldTwo) < 120

You can also use NOW() in place of a field name. 您也可以使用NOW()代替字段名称。

Change it to 将其更改为

timediff(sessions.producer_on,sessions.producer_off) > TIME('00:02:00')

and it should work. 它应该工作。

SELECT * FROM e_email_otp WHERE TIMEDIFF('2019-01-11 10-46-19',`2019-01-11 10-45-19`) <'00:02:00.000000'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM