Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
Home -> Community -> Usenet -> c.d.o.misc -> Re: this cannot be then best way
g wrote:
: I have a date mydate and i want to subtract X working days off
: i was thinking of something like
: loop while x > 0
: if to_char(mydate,'d') < 6 then
: x = x -1
: endif
: mydate :mydate - 1
: endloop
two ideas come to mind
-1-
Keep a table that lists the dates of the holidays and weekends dates for the year (call them off_days)
first_guess = mydate - x/5*7 # account for weekends
non_working = (select count(off_days) between guess and mydate) new_guess = mydate - non_working iterate until the new_guess doesn't change
-2-
fill a table with every work day of the year, and for each day save the number of days worked up to that day (the_date, worked_days)
given mydate,
lookup the number of days worked in the year up to that date
select worked_days from year where the_date= mydate subtract x to find days we want to have worked (call it wanted) select the date that has that many days worked
select the_date from year where worked_days = wanted
$0.10 Received on Fri Jul 14 2006 - 17:31:49 CDT