Link to home
Start Free TrialLog in
Avatar of sky_revolution
sky_revolution

asked on

MySQL WHERE & timestamp help

I have a column called "timestamp" in my mysql table, the column type is "datetime":
Example timestamp format: 2011-12-16 16:51:45

I'm trying to write a SELECT query to only select records with a timestamp within the last 20 minutes of the current time.

How would I do this using PHP?

Thanks
Avatar of Sharath S
Sharath S
Flag of United States of America image

try like this.
select *
  from your_table
 where DATE_SUB(curdate(),INTERVAL 20 MINUTE) <= timestamp

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Greg Alexander
Greg Alexander
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of sky_revolution
sky_revolution

ASKER

Works great, thanks!