date query

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Tarscher

    date query

    Hi all,

    I have a l list of persons and birthdays (stored as a date eg:
    1980-07-11). I want to query the 4 first persons that will have their
    birtday. Can this be done via query?

    Thanks in advance
    Stijn

  • frizzle

    #2
    Re: date query

    Yes.
    If possible, it might be'd better if you remove
    the dashs from the date, anyway:

    Something like the following:

    SELECT * FROM birthdays WHERE birthday < $today ORDER BY birthday DESC
    LIMIT 4

    Comment

    • Colin McKinnon

      #3
      Re: date query

      Tarscher wrote:
      [color=blue]
      > Hi all,
      >
      > I have a l list of persons and birthdays (stored as a date eg:
      > 1980-07-11). I want to query the 4 first persons that will have their
      > birtday. Can this be done via query?
      >
      > Thanks in advance
      > Stijn[/color]

      Probably.

      Unless you're using GDBM or similar you might be better asking the question
      on a forum for your DBMS. You didn't say what that was so I can't point you
      in the right direction.

      C.

      Comment

      • Tarscher

        #4
        Re: date query

        I want to receive the first 4 people that van their birthday after
        today and still having problems. I tried to use
        SELECT naam, birthdays FROM tblperson
        WHERE birthdays <= $today
        ORDER BY DAYOFYEAR(birth days ) LIMIT 4

        $today yyyy-mm-dd

        I have some issues here
        - When I encapsulate $today in '' I don't receive any results
        - When applying the order by clause birthdays all the oldest persons
        are returned
        - When applying the order by clause DAYOFYEAR(birth days) all the
        persons in January are returned

        When I query end of december I also want to get the people that have
        their birthday in January. Will this work with birthdays <= $today?
        I use MySQL

        I hope someone can help me out

        Comment

        • Colin McKinnon

          #5
          Re: date query

          Tarscher spilled the following:
          [color=blue]
          > I want to receive the first 4 people that van their birthday after
          > today and still having problems. I tried to use
          > SELECT naam, birthdays FROM tblperson
          > WHERE birthdays <= $today
          > ORDER BY DAYOFYEAR(birth days ) LIMIT 4
          >
          > $today yyyy-mm-dd
          >
          > I have some issues here
          > - When I encapsulate $today in '' I don't receive any results
          > - When applying the order by clause birthdays all the oldest persons
          > are returned
          > - When applying the order by clause DAYOFYEAR(birth days) all the
          > persons in January are returned
          >
          > When I query end of december I also want to get the people that have
          > their birthday in January. Will this work with birthdays <= $today?
          > I use MySQL
          >[/color]

          Getting there - but you still leave us to do some guessing.

          Try:

          SELECT * FROM tblperson
          WHERE DAYOFYEAR(birth days) >= DAYOFYEAR(CURDA TE())

          C.

          Comment

          Working...