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!

DateAdd Function Question

Status
Not open for further replies.

ronnutter

Technical User
Aug 30, 2001
15
US

i tried this formula:

dateadd("w",5,{voyage_portcall.sail_date})

results should be a date that is 5 weekdays (business days) from the sail date, however the formula is adding 5 calender
days.

i need to add 5 business days to the sail date and i thought
this formula would work.

any ideas,
thanks,
ron
 
Try the below formula if you have CR version 8 or above.


numbervar counts;datevar lastday;datevar firstday;numbervar loops;
firstday:={voyage_portcall.sail_date};

while counts <5 do(
loops:=loops+1;
if dayofweek(firstday+loops)in [2 to 6] then counts:=counts+1);

lastday:=firstday+loops
 
I just looked at the help file for the DateAdd function, and I would have made the same assumption that you may have made.

I read it and thought &quot;w&quot; was week days(Monday thru Friday) and &quot;ww&quot; would be the whole week (Sunday thru Saturday). Not week periods.

w -- Weekday
ww -- Week (7-day period)

 
yes, that is what i thought too.
formula works barron, but i also need to subtract business days. also, sometimes the startdate may fall on a weekend,

further suggestions appreciated
 
The formula will work if the start date is on a weekend. I tested it by assigning &quot;today&quot; to my firstday variable and then set the print date to a date that represented everyday of the week.

Here is a subtracting formula. I kept &quot;today&quot; as my firstdaym. I only had to change it to a subtraction of the loopsm number, but almost forgot to assign different variable names.

numbervar countsm;datevar lastdaym;datevar firstdaym;numbervar loopsm;
firstdaym:=today;

while countsm <5 do(
loopsm:=loopsm+1;
if dayofweek(firstdaym-loopsm)in [2 to 6] then countsm:=countsm+1);

lastdaym:=firstdaym-loopsm
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top