Results 1 to 4 of 4

Thread: Query with date

  1. #1
    Join Date
    Sep 2010
    Posts
    14

    Question Unanswered: Query with date

    I am trying to get all records that have an admitance date of 18 months or longer. right now I use:
    SELECT
    client.cname,
    client.curr_program,
    client.admission
    FROM
    client
    HAVING
    client.curr_program = 'RTC' AND
    client.admission <= '2009-03-17'
    ORDER BY
    client.admission ASC

    Is there a way to have the date (bolded above) auto populate or do I need to change the date every time I run the query? I am using MySQL.

  2. #2
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    first of all, you should use WHERE, not HAVING

    as for the date, sure, you can do it with an expression based on the current date...
    Code:
    SELECT cname
         , admission
      FROM client
     WHERE curr_program = 'RTC' 
       AND admission <= CURRENT_DATE - INTERVAL 18 MONTH
    ORDER 
        BY admission ASC
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  3. #3
    Join Date
    Sep 2010
    Posts
    14

    Talking Thanks!!!

    r937 YOU ROCK!!!!! I have been working 3 days on this and you fixed it with one simple statment! Thanks.

    If you were here I would take you for a beer.

  4. #4
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    you're welcome

    next time, i wouldn't wait 3 whole days

    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •