Home » SQL & PL/SQL » SQL & PL/SQL » Sql statement involving dates
Sql statement involving dates [message #8351] Tue, 12 August 2003 12:24 Go to next message
Tony Grace
Messages: 23
Registered: August 2003
Junior Member
Hi,

I know this is a newbie question but I really need help with this and can't seem to find the exact way in my literature.

I want to create a queries that will grab records by start date within the last 30 and 50 days.

the start date is in a table with a column assigne start date...I just don't know how I can query against the data so I can pull records that have a start date of within the last 30 or 50 of whenever this query gets run.

Can anyone help?

Tony
Re: Sql statement involving dates [message #8352 is a reply to message #8351] Tue, 12 August 2003 12:34 Go to previous messageGo to next message
Todd Barry
Messages: 4819
Registered: August 2001
Senior Member
select *
  from t
 where start_date >= (trunc(sysdate) - 30);  -- or 50


This would pick up any rows with a start date greater than 30 days ago (12:00am).
Re: Sql statement involving dates [message #8353 is a reply to message #8352] Tue, 12 August 2003 12:47 Go to previous messageGo to next message
Tony Grace
Messages: 23
Registered: August 2003
Junior Member
It sorta worked, except soem data in the table have a future start date and I need to exclude those from my query. How can I make the query include only the last 30 days....

thanks a bunch for your help
Re: Sql statement involving dates [message #8354 is a reply to message #8353] Tue, 12 August 2003 15:31 Go to previous message
Todd Barry
Messages: 4819
Registered: August 2001
Senior Member
select *  
  from t
 where start_date between (trunc(sysdate) - 30) and sysdate;


This would pick up any rows from 30 days ago (12:00am) and the current time today.
Previous Topic: Getting column names
Next Topic: question
Goto Forum:
  


Current Time: Thu Apr 25 14:15:17 CDT 2024