views:

88

answers:

2

Hi,

How do I query a mysql db to return all records with a datetime older than 1 week ago. Note that the datetime table stores everything in UTC, and i should be comparing it in that itself...

Jusst to be clear - I'm looking for a pure mysql query

A: 

SELECT SUBDATE('2008-01-02', 7);

OR

SELECT SUBDATE(now(), INTERVAL 1 week);

Result:

2007-12-26

Michael Pakhantsov
how do i do 7 days ago from today, with date and time markings...
tzmatt7447
+2  A: 
SELECT * FROM tbl WHERE datetime < NOW() - INTERVAL 1 WEEK

If your table stores datetimes in different timezone than what NOW() returns, you can use UTC_TIMESTAMP() instead to get the timestamp in UTC.

reko_t
works excellently! thanks!
tzmatt7447