Forum Moderators: coopster

Message Too Old, No Replies

date range help

         

jm21

6:48 am on Nov 10, 2009 (gmt 0)

10+ Year Member



Need help guys. Am working on a script similar to the Facebook one where you can see upcoming birthdays for friends. I have a simple table with birthday id, name and date in date format.

I want the script to list the upcoming birthdays in the next 2 weeks, to do my initial idea was to write a query similar to 'SELECT * FROM bdays WHERE Bday_Date BETWEEN '$today' AND '$enddate', however because the because the years differ depending on each persons birthday I don't get a result on my query. Basically i need to search based on month/day not year/month/day which is what I have on the table. Any ideas on how to do this? Have tried using wildcards to replace the year but that doesnt help. Anyone got an idea?

dreamcatcher

7:45 am on Nov 10, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



SELECT * FROM bdays WHERE MONTH(Bday_Date) = '$month' AND DAY(Bday_Date) = '$day';

dc

jm21

7:56 am on Nov 10, 2009 (gmt 0)

10+ Year Member



Thanks dc, this gives me the bday of a person who's having a bday today however i want to get the upcoming birthdays for the next 14 days so I need to get results where the bday falls from today to the next 14 days. Any ideas? Have trolled mysql date functions with no success

jm21

8:11 am on Nov 10, 2009 (gmt 0)

10+ Year Member



Got a solution from the mysql forums - do a sql query like SELECT * FROM bdays where DAYOFYEAR( curdate() ) <= dayofyear( `Bday_Date` )
AND DAYOFYEAR( curdate() ) +14 >= dayofyear( `Bday_Date` )

rocknbil

7:00 pm on Nov 10, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Don't ignore the power of mySQL between [dev.mysql.com]. :-)