In a message dated 98-12-26 23:52:16 EST, you write:
I would like to be able to use relative dates as conditions for date fields.
For instance, I may want to see all invoices dated or
or or , etc… etc… I do not want to have to
hard
code dates into the conditions every time I want to use them.
Hi, Lisa…
You can do a variety of tricks with objects to accomplish this. If memory serves, you are using the Oracle database. You can use objects that reference the SYSDATE value to accomplish what you are asking for.
For example, a YESTERDAY object would be easy to do as:
SYSDATE - 1
However, this does not take into account weekends. Yesterday for Sunday would be defined as Saturday. Yesterday for Monday would be defined as Sunday. If you want “yesterday” for Monday to be Friday, then you have to get a little fancier. Something like:
DECODE(TO_CHAR(some_date,‘DAY’), ‘MONDAY’, SYSDATE-3, SYSDATE-1)
This will decode the day name of a date. If the day name is MONDAY, then the formula will give you the previous Friday’s date as “yesterday”. For any other day (including Sunday) it will return the true “yesterday”. You can add to this to adjust for Sunday as well if you like.
To do Last Week it gets a little more complicated. Something that I have used in the past goes something like this:
some_date BETWEEN NEXT_DAY(TRUNC(SYSDATE-8), ‘SUNDAY’) and NEXT_DAY(TRUNC(SYSDATE-2),‘SATURDAY’)
This formula will allow you to check for a date between last Sunday and last Saturday. No matter which day this week you run the query, the date range will be from Last Sunday to Last Saturday.
The Last Month object requires the ADD_MONTHS() function. You can build a month range something like:
some_date between LAST_DATE(ADD_MONTHS(sysdate, -2))+1 and LAST_DATE(ADD_MONTHS(SYSDATE, -1))
This formula will get you the last date from two months ago and add one, giving you the first date of last month. The other part of the function gets the last day from the previous month.
There is more than one way to do these various formulas, but these should work for you, or at least get you started!
Regards,
Dave Rathbun
Integra Solutions
www.islink.com
Listserv Archives (BOB member since 2002-06-25)