Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Relative dates in SQL?

Status
Not open for further replies.

Dan01

Programmer
Jun 14, 2001
439
US
Hi, I have a monthly report that captures the previous 6 months. Each month, the dates roll forward one month for both start and end dates. Can SQL handle relative dates? For example, Today minus 1 month for the end date, and today minus 7 months for the start date. To complicate things even more, the dates are stored as YYYYMM, e.g., 200101, 200102, 200103, etc. Thanks, Dan.
 
Hi Dan,

You can use the following range for the last six months, this will exclude the current month.
(DateYyMm>=add_months(CurYyMm, -6) and
DateYyMm<=CurYyMm)

Hope this helps, if not send me the sample SQL and I will check it out.

Regards
 
Thanks for the post OraCool. What environment are you working in? Would this code work in JetSQL? Dan.
 
Hi Dan

I am working in Oracle, What is JetSql and what RDBMS is it used on?

Thanks
 
I figured you were working on a sophisticated platform, and I thought it might be oracle (OraCool). JetSQL is Microsoft Access SQL. Thanks, Dan.
 
You will probably be better off posting this in an Access forum. Access uses a very non-standard version of SQL
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top