Purpose Add or subtract
working days (omit Saturday and Sunday)
Solution
GuiXT
// in: date1, any date in a valid SAP date format
// in: n, any positive or negative number
// out: date2, n working days added (no Saturday or Sunday),
// same format as date1
Set V[date1] "&V[today_d.m.y]" // sample date
Set V[n] 30 // sample day count
// determine full week days (5 working days per week)
Set V[w] 0
Set V[d] &V[n]
if V[n>4] or V[n<-4]
if V[n>4]
Set V[w] &V[n] - 2
else
Set V[w] &V[n] + 2
endif
Set V[w] &V[w] / 5 decimals=0
Set V[d] &V[w] * 5
Set V[d] &V[n] - &V[d]
Set V[w] &V[w] * 7
endif
// add full weeks
Set V[date2] &V[date1] + &V[w]
// determine day of week
// 0=Monday, 1=Tuesday, ...6=Sunday
Set V[absdate] &V[date2] * 1
Set V[day_of_week] &V[absdate] / 7 decimals=0
Set V[day_of_week] &V[day_of_week] * 7
Set V[day_of_week] &V[absdate] - &V[day_of_week]
if V[day_of_week<0]
Set V[day_of_week] &V[day_of_week] + 7
endif
// weekend to skip?
Set V[day_of_week] &V[day_of_week] + &V[d]
if V[n>0] and V[day_of_week>4]
Set V[date2] &V[date2] + 2
endif
if V[n<0] and V[day_of_week<0]
Set V[date2] &V[date2] - 2
endif
// add remaining days
Set V[date2] &V[date2] + &V[d]
// done, display test message
Message "&V[date1], plus &V[n] working days: &V[date2]"