Jump to content

pulling birthdays from mysql


lional

Recommended Posts

I have two fields in a database table one for day of birth and one for month of birth. I would like to pull whose birthday it is today, but if the birthday falls on a monday I would like to include the previous 2 days in the query. The day of birth is saved in numerical form 1 - 31, and the month is January - December. I am not interested in the year. I am not sure how to pull this info from the database

 

Thanks in advance

 

Lional

Link to comment
Share on other sites


|   SELECT * FROM `friends` WHERE (
|   EXTRACT(MONTH FROM `birthday` ) = EXTRACT(MONTH FROM 
|   CURDATE()) 
|   AND 
|   DAYOFMONTH(`birthday`) >= DAYOFMONTH(CURDATE()) 
|   AND 
|   DAYOFMONTH(`birthday`) <= (DAYOFMONTH(CURDATE()) +  15) 
|   ) 
|
|   OR (
|   EXTRACT(MONTH FROM `birthday`) = EXTRACT(MONTH FROM 
|   ADDDATE(CURDATE(), INTERVAL 15 DAY))  
|   AND 
|   DAYOFMONTH(`birthday`) <= DAYOFMONTH(ADDDATE(CURDATE(), 
|   INTERVAL 15 DAY))
|   )

 

url bottom page read please.

 

http://dev.mysql.com/doc/refman/5.1/en/date-and-time-functions.html

Link to comment
Share on other sites

  • 2 weeks later...

I am a bit confused with the SUBDATE. I have a field in the mysql table called display_date of type varchar, and it is stored in the format of yyyy-mm-dd. On your code above where am I referencing that it is from this field that I would like to compare the dates.

 

Thanks

 

Lional

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.