Note: This was originally posted by an inactive account. Content was preserved by moving under an admin account.
Originally posted by: andycooperI have created a simple example using the BRAINScript link above: -
node:Start_Date_Close_Date
bretype:core::Static Data
editor:Label=Start Date, Close Date
editor:sortkey=54ad3589056c6e1e_2
output:@40fe6c55598828e5/=
prop:StaticData=<<EOX
Start Date:date,Close Date:date
2015-01-05,2015-01-06
2015-01-04,2015-01-06
2015-01-03,2015-01-06
2015-01-02,2015-01-06
EOX
editor:XY=390,100
end:Start_Date_Close_Date
node:Calculate_Workdays__BRAINScript
bretype:core::Filter
editor:Label=Calculate Workdays - BRAINScript
editor:sortkey=54b4de8b50cf3082
input:@40fd2c74167f1ca2/=Start_Date_Close_Date.40fe6c55598828e5
output:@40fd2c7420761db6/=
prop:Script=<<EOX
weekDays = 1 + (dateSubtract('Close Date','Start Date') * 5 - ('Start Date'.weekday()-'Close Date'.weekday()) * 2) / 7;
if ('Close Date'.weekday() == 6) then weekDays = weekDays -1
if ('Start Date'.weekday() == 0) then weekDays = weekDays -1
emit 'Start Date'
emit 'Close Date'
emit weekDays.int() as "weekDays"
EOX
editor:XY=470,100
end:Calculate_Workdays__BRAINScript
If you wanted to exclude the start date itself then you could simply change the emit line to emit weekDays.int() -1 as "weekDays"
Thanks
Andy