Jumpy09 Posted October 3, 2010 Share Posted October 3, 2010 I posted this in another post, but that was located in PHP Help, so I decided I may get better results if I posted it on it's own in MySQL Help. $database is a class, just in case someone questions it. Posted this way because the code wasn't wrapping around. MySQL Version I believe is 5.0.45 uid = User Identification, Auto-Incrementing, Master Key, INT bdaytest = DATE - YYYY-MM-DD $query = $database->execute(" SELECT uid, bdaytest FROM `users` WHERE DATE_FORMAT(bdaytest, '%m%d') BETWEEN DATE_FORMAT(CURDATE(), '%m%d') AND CONCAT(DATE_ADD( CURDATE(), INTERVAL 7 DAY), DATE_FORMAT('%m%d')) ORDER BY DATE_FORMAT(bdaytest, '%m%d') ASC "); The problem with this query is I am getting the following error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ')) ORDER BY DATE_FORMAT(bdaytest, '%m%d') ASC' at line 1 This type of Query is a little bit out of my league of expertise, but I came up with it after finding a few results on Google about selecting queries by Date. I have not seen this exact query, but I figured it would work either way. The error starts at the )) part of CONCAT, which is throwing me off from being able to properly debug the error. If I missed any information, please let me know. I just found the Sticky Guidelines. Any suggestions on why it isn't working? Quote Link to comment https://forums.phpfreaks.com/topic/215024-query-to-pull-users-by-birthday-between-now-and-1-week-from-now/ Share on other sites More sharing options...
Jumpy09 Posted October 3, 2010 Author Share Posted October 3, 2010 GOT IT SELECT uid, bdaytest FROM `users` WHERE DATE_FORMAT(bdaytest, '%m%d') BETWEEN DATE_FORMAT(CURDATE(), '%m%d') AND DATE_FORMAT(DATE_ADD( CURDATE(), INTERVAL 3 DAY), '%m%d') ORDER BY DATE_FORMAT(bdaytest, '%m%d') ASC I'm sure others could use a query like this. Just change the INTERVAL period to pull up people by birthday, I have a function that pulls usernames from the uid... so make sure you pull all information you need to relay on your website. Quote Link to comment https://forums.phpfreaks.com/topic/215024-query-to-pull-users-by-birthday-between-now-and-1-week-from-now/#findComment-1118498 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.