View Single Post
Old 12-13-2012, 02:52 PM   PM User | #6
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,650
Thanks: 4
Thanked 2,451 Times in 2,420 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
That's because of the operator in use. If you want to do that using PHP code, you need to select a date that is BETWEEN two other dates (one three weeks ago and one two weeks ago). Otherwise you get everything from three weeks ago to current.
MySQL can do that too, just use the date_add/date_sub or the overloads of the -/+ operators: WHERE datetxt BETWEEN CURDATE() - INTERVAL 3 WEEK AND CURDATE() - INTERVAL 2 WEEK looks like it would work.

YEARWEEK would work, except you need to check for the YEAR and you need to check when the current week is <= the provided week in the year (since then you have to go back and check last years records). This is easier to do if you manipulate the field itself, but you will slow down the query in doing so. So I think using BETWEEN is a better option.
Fou-Lu is offline   Reply With Quote