![]() | |
![]() |
| | Thread Tools | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
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 any ideas |
#3
| |||
| |||
|
|
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 any ideas If X tends to be large (>2weeks), then save a few passes thru the loop by --- computing the whole weeks whole_weeks := ( 7* (X/5) ) --- must use integer arithmetic mydate := mydate - whole_weeks x := mod(x,5) --- then put your loop here: HTH, ed |
#4
| |||
| |||
|
|
What if you have some holiday in between? |
#5
| |||
| |||
|
|
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 any ideas |
#6
| |||
| |||
|
#7
| |||
| |||
|
|
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 any ideas Just a quick note: TO_CHAR does not produce a number and essentially none of the code, above, is valid. It will never run in Oracle. What product do you have? |
#8
| |||
| |||
|
|
DA Morgan wrote: 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 any ideas Just a quick note: TO_CHAR does not produce a number and essentially none of the code, above, is valid. It will never run in Oracle. What product do you have? It will, as PL/SQL engine will implicitly apply TO_NUMBER() to the result of TO_CHAR() in attempt to match types of the values being compared. Not a good idea to rely on implicit type conversion though (at least until 10g where it seems to be more efficient than explicit conversion sometimes.) Regards, Vladimir M. Zakharychev |
#9
| |||
| |||
|
|
Vladimir M. Zakharychev wrote: DA Morgan wrote: 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 any ideas Just a quick note: TO_CHAR does not produce a number and essentially none of the code, above, is valid. It will never run in Oracle. What product do you have? It will, as PL/SQL engine will implicitly apply TO_NUMBER() to the result of TO_CHAR() in attempt to match types of the values being compared. Not a good idea to rely on implicit type conversion though (at least until 10g where it seems to be more efficient than explicit conversion sometimes.) Regards, Vladimir M. Zakharychev I took it as pseudocode as it will not work as written. Just look at the assignment statements. Thanks all |
![]() |
| Thread Tools | |
| Display Modes | |
| |