If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > Query with date

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 09-20-10, 10:32
lightfju lightfju is offline
Registered User
 
Join Date: Sep 2010
Posts: 14
Question 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.
Reply With Quote
  #2 (permalink)  
Old 09-20-10, 10:57
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,525
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
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #3 (permalink)  
Old 09-20-10, 13:14
lightfju lightfju is offline
Registered User
 
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.
Reply With Quote
  #4 (permalink)  
Old 09-20-10, 13:37
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,525
you're welcome

next time, i wouldn't wait 3 whole days

__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
Reply

Tags
date, mysql, query

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On