views:

61

answers:

5

I need to select from a table all rows that have date_added between CURDATE() and 6 weeks ago.

Help please.

+3  A: 
SELECT  *
FROM    mytable
WHERE   date_added BETWEEN CURDATE() - INTERVAL 6 WEEK AND CURDATE()
Quassnoi
+2  A: 
SELECT *
FROM a_table
WHERE date_added BETWEEN DATE_SUB(CURDATE(), INTERVAL 6 WEEK) AND CURDATE()
Håvard S
+1  A: 
SELECT * FROM table_name WHERE TO_DAYS(NOW()) - TO_DAYS(date_added) <= 42
Alexander.Plutov
Ha! 42 used *with* reason!
Hans Kesting
7 days in week. 6 weeks... Function TO_DAYS work with days.
Alexander.Plutov
+1 @Alexander: He wasn't asking how you got the 42, I guess he's a fan of Hitchhiker's Guide to the Galaxy (aren't we all :p).
wimvds
A: 

SELECT * FROM table_name WHERE DATEDIFF(NOW(),date_added)<=42

Pradeep
A: 

if u use dates in one year

select date_format(date, '%u') from tab

where (date_format(date, '%u')-date_format(now(), '%u'))>6

if u use dates with dufferent years

U don't have to use dates with anoter year. u can use

select

date_format(date, '%u') from tab

where (date_format(date, '%u')-date_format(now(), '%u'))>6

and

date_format(date, '%u') from tab

where (date_format(date, '%Y')-date_format(now(), '%Y'))=0

u can optimize query with join if u want. I think u now how to do it

Mishuko