bschultz Posted April 13, 2013 Share Posted April 13, 2013 I have a column (DATE) for bithdays...how can I select in MYSQL which birthdays were last week...and the upcoming week? I found this...but it's only for the upcoming week...not last week too... $sql = 'SELECT * FROM table WHERE WEEK(birthdate) = WEEK(DATE_ADD(NOW(), INTERVAL 7 DAY))'; How can I adjust this to include last week too? Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/276888-birthdays-last-week-and-this-week/ Share on other sites More sharing options...
Jessica Posted April 13, 2013 Share Posted April 13, 2013 So if you add 7 days to get this week, what would you do to get last week? Quote Link to comment https://forums.phpfreaks.com/topic/276888-birthdays-last-week-and-this-week/#findComment-1424502 Share on other sites More sharing options...
bschultz Posted April 13, 2013 Author Share Posted April 13, 2013 I tried... $sql = 'SELECT * FROM table WHERE WEEK(birthdate) = WEEK(DATE_ADD(NOW(), INTERVAL 7 DAY)) AND WEEK(birthdate) = WEEK(DATE_ADD(NOW(), INTERVAL -7 DAY))'; And I got back results from March... Quote Link to comment https://forums.phpfreaks.com/topic/276888-birthdays-last-week-and-this-week/#findComment-1424505 Share on other sites More sharing options...
Jessica Posted April 13, 2013 Share Posted April 13, 2013 Instead of adding 7 days, try adding no days. Don't add anything. Or maybe minus 1. Quote Link to comment https://forums.phpfreaks.com/topic/276888-birthdays-last-week-and-this-week/#findComment-1424506 Share on other sites More sharing options...
l0gic Posted April 13, 2013 Share Posted April 13, 2013 (edited) $sql = 'SELECT * FROM table WHERE WEEK(birthdate) = WEEK(DATE_ADD(NOW(), INTERVAL 7 DAY)) AND WEEK(birthdate) = WEEK(DATE_ADD(NOW(), INTERVAL -7 DAY))'; AND.... OR? This week can't be this week and next week, and even last week can it? I guess it could be this week or next week, or even last week. Edited April 13, 2013 by l0gic Quote Link to comment https://forums.phpfreaks.com/topic/276888-birthdays-last-week-and-this-week/#findComment-1424522 Share on other sites More sharing options...
jcbones Posted April 13, 2013 Share Posted April 13, 2013 Probably should be BETWEEN ... AND. Quote Link to comment https://forums.phpfreaks.com/topic/276888-birthdays-last-week-and-this-week/#findComment-1424572 Share on other sites More sharing options...
Solution bschultz Posted April 13, 2013 Author Solution Share Posted April 13, 2013 I changed plans and went with GET variables to set the start date and the end date of the time frame wanted....more flexible anyway. Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/276888-birthdays-last-week-and-this-week/#findComment-1424596 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.