markzzz
markzzz

Reputation: 47945

MySql - Select value with datetime = datetime-3 minuts

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>'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?

Upvotes: 0

Views: 172

Answers (3)

The Scrum Meister
The Scrum Meister

Reputation: 30111

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

Upvotes: 1

Sarfraz
Sarfraz

Reputation: 382716

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

Upvotes: 1

Byron Whitlock
Byron Whitlock

Reputation: 53871

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'

Upvotes: 3

Related Questions