Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

timediff is greater than 2 minutes

Tags:

mysql

I am trying to write a query where I can eliminate a timediff of less than 2 minutes. 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. Can anyone help - many thanks

like image 711
al. Avatar asked Nov 15 '09 18:11

al.


2 Answers

Change it to

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

and it should work.

like image 179
NaijaBoy Avatar answered Oct 04 '22 22:10

NaijaBoy


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.

like image 42
MattieShoes Avatar answered Oct 04 '22 22:10

MattieShoes