开发者

MySql - Select value with datetime = datetime-3 minuts

开发者 https://www.devze.com 2023-02-01 00:47 出处:网络
I have a table with with 3 fields : id (int 11), user (varchar 255) and data (DATETIME). I need somethings like :

I have a table with with 3 fields : id (int 11), user (varchar 255) and data (DATETIME).

I need somethings like :

SELECT user FROM counter WHERE date&g开发者_StackOverflowt;'ACTUAL DATA - 3 MINUTS'

So i can return all username with data between the actual data - 3 minuts and the actual data. Like return all username between 2010-12-22 18:32:00 and 2010-12-22 18:35:00

How can I do it with MySql?


Yes, you need to use the SUBTIME() function.

SELECT user FROM counter WHERE date > SUBTIME( 'yourdate', '0:03' );

EDIT

Since you changed your question here is an updated answer:

SELECT user FROM counter WHERE date BETWEEN SUBTIME( 'yourdate', '0:03' ) and 'yourdate'


SELECT user FROM counter WHERE date > DATE_SUB(dateColumn, INTERVAL 3 MINUTE)


SELECT user FROM counter WHERE date BETWEEN NOW() - INTERVAL 3 MINUTE AND NOW()
0

精彩评论

暂无评论...
验证码 换一张
取 消