upcoming birthdays query

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • onlyshanks28
    New Member
    • Oct 2008
    • 13

    upcoming birthdays query

    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)>=mon th(curdate()) limit 3;

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

    Shashank
  • r035198x
    MVP
    • Sep 2006
    • 13225

    #2
    Why are you taking the month parts?
    Try something like [CODE=mysql]where dob >= curdate() order by dob limit 3;[/CODE]

    Comment

    • onlyshanks28
      New Member
      • Oct 2008
      • 13

      #3
      Originally posted by r035198x
      Why are you taking the month parts?
      Try something like [CODE=mysql]where dob >= curdate() order by dob limit 3;[/CODE]
      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( )

      Comment

      • onlyshanks28
        New Member
        • Oct 2008
        • 13

        #4
        for it we have to use three query subsequently

        1) select name,date from days_to_remembe r where month(date)=mon th(curdate()) AND date(date)>=dat e(curdate()) order by date asc;

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



        2) select name,date from days_to_remembe r where month(date)>mon th(curdate()) order by date asc;

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

        3) select name,date from days_to_remembe r order by date asc;

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


        use a counter element to limit the number of elements

        Comment

        • r035198x
          MVP
          • Sep 2006
          • 13225

          #5
          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.

          Comment

          • onlyshanks28
            New Member
            • Oct 2008
            • 13

            #6
            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

            Comment

            • RahulGuptaRG
              New Member
              • Aug 2012
              • 1

              #7
              great
              Thanks a lot.

              Comment

              Working...