I have a MySQL database table, with a unix timestamp field. I am wondering how to get the most recent complete 13 weeks?
Update
But I need to opt out the current week. So I need the last complete(that ended in past or today) 13 weeks.
I have a MySQL database table, with a unix timestamp field. I am wondering how to get the most recent complete 13 weeks?
Update
But I need to opt out the current week. So I need the last complete(that ended in past or today) 13 weeks.
WHERE FROM_UNIXTIME(timestamp) > DATE_SUB(FROM_UNIXTIME(timestamp), INTERVAL 13 WEEKS)
If you want to exclude the current week you can do:
WHERE FROM_UNIXTIME(timestamp) < DATE_SUB(NOW(), INTERVAL 1 WEEKS)
SELECT *,FROM_UNIXTIME(time) AS TS FROM MyTable WHERE TS > DATE_SUB(TS, INTERVAL 13 WEEKS)
Think that should work
http://dev.mysql.com/doc/refman/5.1/en/date-and-time-functions.html#function_date-add
SELECT * FROM foo WHERE created >= DATE_SUB(NOW(), INTERVAL 13 WEEK);