Working Days using syntax - solved

Moderators: statman, Analyst Techy, andris, Fierce, GerineL, Smash

KeithMurray
Posts: 16
Joined: Fri Feb 21, 2014 1:12 pm

Working Days using syntax - solved

Postby KeithMurray » Tue Feb 25, 2014 10:09 am

Problem solved. Posting syntax in case it's of use to anyone else.

The code can also be modified to take account of known public holidays, if required.

If date1 is start date and date2 is end date, both formatted as dates ......

Paste following into syntax.

comment N determines how many times round the loop.
compute N = 0.

comment number of non working days.
compute weekend = 0.

comment number of working days.
compute workday = 0.

comment date1 is start date, date2 is end date.
comment Cduration difference between date1 and date2.
COMPUTE Cduration = DATEDIFF(date2,date1,"days").


comment loopdate increments starting date one day at a time until end date is reached.
compute loopdate = date1.
execute.

set mxloops = 1000.
loop if (date2 >= date1).
compute N = N+1.
if (XDATE.WKDAY(loopdate) = 1) weekend = weekend+1.
if (XDATE.WKDAY(loopdate) = 2) workday = workday+1.
if (XDATE.WKDAY(loopdate) = 3) workday = workday+1.
if (XDATE.WKDAY(loopdate) = 4) workday = workday+1.
if (XDATE.WKDAY(loopdate) = 5) workday = workday+1.
if (XDATE.WKDAY(loopdate) = 6) workday = workday+1.
if (XDATE.WKDAY(loopdate) = 7) weekend = weekend+1.
compute loopdate = loopdate + 86400.
end loop if (N >= Cduration).
execute.

delete variables N loopdate.
alter type weekend workday Cduration (F4.0).

end paste

Who is online

Users browsing this forum: No registered users and 1 guest

cron