Afficher un message
Vieux 29/09/2007, 23h22   #2
Paul Lautman
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: SELECT all records that occurred in the last five minutes or less

andrecal wrote:
> I have a table with a TIMESTAMP entry, and I would like to find a
> query that will look at this table and only return results that shows
> the TIMESTAMP to be five minutes ago or less.
>
> Something along these lines:
> SELECT * FROM table_name WHERE entry_date BETWEEN NOW() AND NOW()-5
> minutes ago
>
> entry_date is a full timestamp
>
> any appreciated,
> AN


Hmm, you say "any appreciated", yet you have completely ignored the
superb given by the developers when they wrote the section "Date and
Time Functions" in the MySQL user manual
(http://dev.mysql.com/doc/refman/5.0/...functions.html)!

I just went there to find the answer.

SELECT
*
FROM table_name
WHERE entry_date > date_sub( now( ) , INTERVAL 5 MINUTE )

or you may prefer:

SELECT
*
FROM table_name
WHERE entry_date > now( ) - INTERVAL 5 MINUTE


  Réponse avec citation
 
Page generated in 0,62265 seconds with 9 queries