Connecting Tech Pros Worldwide Forums | Help | Site Map

upcoming birthdays query

Newbie
 
Join Date: Oct 2008
Posts: 12
#1: Oct 30 '08
Hi

I have a database birthday containing name and DOB,
I want to find the query which can display 3 latest birth day.

I tried
select name,date from birthday where month(dob)>=month(curdate()) limit 3;

But the problem here is that on 31-December-2008 it will not display the birthdays on January.

Shashank
Lives Here
 
Join Date: Sep 2006
Posts: 12,070
#2: Oct 30 '08

re: upcoming birthdays query


Why are you taking the month parts?
Try something like
Expand|Select|Wrap|Line Numbers
  1. where dob >= curdate() order by dob limit 3;
Newbie
 
Join Date: Oct 2008
Posts: 12
#3: Oct 30 '08

re: upcoming birthdays query


Quote:

Originally Posted by r035198x

Why are you taking the month parts?
Try something like

Expand|Select|Wrap|Line Numbers
  1. where dob >= curdate() order by dob limit 3;

Problem with it is:

If Current date is 31 december 08

then it will not display birthday in the moth if january 09

Also dob can never be more than currdate( )

MY dob is 28-08-1986(suppose) it cant be greater than currdate( )
Newbie
 
Join Date: Oct 2008
Posts: 12
#4: Oct 30 '08

re: upcoming birthdays query


for it we have to use three query subsequently

1) select name,date from days_to_remember where month(date)=month(curdate()) AND date(date)>=date(curdate()) order by date asc;

-----it will give upcomng bdays of same months---



2) select name,date from days_to_remember where month(date)>month(curdate()) order by date asc;

-----it will give upcomng bdays of next months---

3) select name,date from days_to_remember order by date asc;

-----it will give upcomng bdays of next year---


use a counter element to limit the number of elements
Lives Here
 
Join Date: Sep 2006
Posts: 12,070
#5: Oct 30 '08

re: upcoming birthdays query


Quote:

Originally Posted by onlyshanks28

Problem with it is:

If Current date is 31 december 08

then it will not display birthday in the moth if january 09

Also dob can never be more than currdate( )

MY dob is 28-08-1986(suppose) it cant be greater than currdate( )

Oh silly me. I get your point now. The year part should not be included in the comparison.
Newbie
 
Join Date: Oct 2008
Posts: 12
#6: Oct 31 '08

re: upcoming birthdays query


Quote:

Originally Posted by r035198x

Oh silly me. I get your point now. The year part should not be included in the comparison.

thats correct
but
we do have to take into cosideration the year when the current date is
31-dec-2008..

the above 3 queries that i have given will do that perfectly
Reply


Similar MySQL Database bytes