Solved

Subtract from System Date (SYSDATE)

Posted on 1998-04-01
3
1,651 Views
Last Modified: 2008-03-17
Hi I wanted to do a sql statement that pick entries between a certain date.  I wanted to get all the records that were less than the current date and that were > currentdate - 7.

Is there a way to do this with oracle or do I have to do it on
the programmers side, I am using ASP for the language

  select * from ennadm.menu, ennadm.cafetr where menu.cafetr_no = cafetr.cafetr_no and
  menu.wk_begin_dt < SYSDATE and ????


Thanks for any help.
Arthur
0
Comment
Question by:vbguy
3 Comments
 
LVL 2

Accepted Solution

by:
frankr earned 100 total points
ID: 1082970
Replace the ???? in your statement with

menu.wk_begin_dt > SYSDATE - 7

You can perform date arithmetic directly by adding or subtracting from a date in days.  
Note that the ADD_MONTHS function is available to deal with the situation where the number of days might be variable (e.g. if you need to add 1 year to a date, and don't want to worry about calculating for leap years explicitly).
0
 

Author Comment

by:vbguy
ID: 1082971
Thanks for your help
0
 

Expert Comment

by:ananth
ID: 1082972
Elegent programming would be
menu.wk_begin_dt between sysdate-7  and sysdate.
This is commonly used to find the product/service prices on date of sales from a product/services price table. Hope this helps
0

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Why doesn't the Oracle optimizer use my index? Querying too much data Most Oracle developers know that an index is useful when you can use it to restrict your result set to a small number of the total rows in a table. So, the obvious side…
Working with Network Access Control Lists in Oracle 11g (part 2) Part 1: http://www.e-e.com/A_8429.html Previously, I introduced the basics of network ACL's including how to create, delete and modify entries to allow and deny access.  For many…
This video shows how to Export data from an Oracle database using the Original Export Utility.  The corresponding Import utility, which works the same way is referenced, but not demonstrated.
This video shows how to configure and send email from and Oracle database using both UTL_SMTP and UTL_MAIL, as well as comparing UTL_SMTP to a manual SMTP conversation with a mail server.

806 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question