Archive for January, 2018

How to subtract a number of working days from a date field

Tuesday, January 16th, 2018

Version:  (DataEase DOS or Windows) and Ffenics

The first step is to deduct the number of days to the original date.
OrigDate – WorkingDays
Next the number of weekends need to be derived, simply by dividing the number of WorkingDays by the number of working days in a week, rounded down to get rid of decimal place and then multiplying that by the number of days in weekend.
floor ( WorkingDays / 5 ) * 2
Finally, we need to ensure that the resulting date is not a weekend. Do this by getting the remainder of the WorkingDays divided by the number of days in a week, deducting that from the original date and if that is a weekend, include the number of days in a weekend into the calculation.
if ( weekday ( OrigDate – mod ( WorkingDays , 5 ) ) > 5 , 2  , 0  )
The completed field derivation is:
OrigDate – WorkingDays –
floor ( WorkingDays / 5 ) * 2 )
if ( weekday ( OrigDate – mod ( WorkingDays , 5 ) ) > 5 , 2 , 0 )