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
https://forums.phpfreaks.com/topic/150288-pulling-birthdays-from-mysql/
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

  • 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

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.