Jump to content

Query to pull users by birthday between NOW and 1 WEEK from NOW!


Jumpy09

Recommended Posts

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?

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.