Hi I have a table with a date field and some other information. I want to select all entries from the past week, (week start from Sunday).
table values:
id date
2 2011-05-14 09:17:25
5 2011-05-16 09:17:25
6 2011-05-17 09:17:25
8 2011-05-20 09:17:25
15 2011-05-22 09:17:25
I want to select all ids from last week, expected output is 5, 6, 8. (id 2 not in last week, and id 15 is in current week.)
How to write and SQL Query for the same.
SELECT id FROM tbl WHERE WEEK(date, 0) = WEEK(NOW(), 0) - 1
for weeks, but I guess his target is not real calendar weeks. At least he didn't mention s/t like ISO-8601, or whether he wants turn of the year to be taken into consideration. – Jürgen ThelenWHERE table.column >= DATE(NOW()) - INTERVAL 7 DAY
– Connor Leech