calculate business days
AnsweredHi all
I'm hoping you can help me... I'm looking for a way to calculate a due date based on two separate fields. Field one is the start date, and field two is the number of business days we have to compete the task. The resulting calculation should give the appropriate due date based on those two fields. Any thoughts on how this can be accomplished?
-
Hello Rahil,
try something like this:
Version 1 adds only the # of days, regradless weekends:N = [number of business days]
S = [StartDate]
moment(S).add(N, "days").format('DD.MM.YYYY')
Version 2 adds business days only:
N = [number of business days]
S = [StartDate]
function addWeekdays(date, days) {
date = moment(S);
while (days > 1) {
date = date.add(1, 'days');
if (date.isoWeekday() !== 6 && date.isoWeekday() !== 7) { days -= 1;
}
}
return date;
}
var date = addWeekdays(moment(),N);
moment(date).format("DD.MM.YYYY | dddd ")The
format
term you can change like you want.
The terms in [...] need to be replaced with your field names that you have in your app. without square bracketsCheers,
Rainer -
No, you'll get the calculated date as a text string and you can't change this calculation field from text to date.
If you use the Podio extension Globiflow you can transfer automatically the result from this calculation field into a date field.
For that you have to create a Podio date field "Due date" in your app, rename the calculation field where you calculate the due date to "Calc Due Date" and put it to the end of the template as a "help field", then transfer with Globiflow the result into the real date field (that can be shown in a calendar). -
Hello Alain,
in Globiflow you should create 2 flows in the app where you want to calculate the due date.
Flow1:
Trigger: when a new item is created
Action:
Update this item
in field [DueDate] = calcdate ("Y-m-d", strtotime( [field-token calc dueDate ))."00:00:00"
Flow 2:
Trigger. When an item is update
Action: same as flow 1.Depending on your individual workflow you can set filters (e.g. for flow 2: If [number of business days] hast just changed - or: if [startDate] hast just changed - you can't set such a filter on calculation fields, cause changes there didn't fire a flow).
-
Hi David,
I would do it like I've described it in my posting here :
https://help.podio.com/hc/communities/public/questions/202828487-Calculating-workdays?locale=en-usRainer
-
Hi Rainer! Thanks for sharing your script. I use the Version2 but have a little issue.
Eg: Add 5 business days. Sometimes, it count the starting day (eg start date 1/01/2016 calc, end date = 05/01/2016) and sometimes, it add 5 days after (eg start date 01/01/2106 calc end date = 06/01/2016.)
I'm am doing something wrong?
Thanks
Please sign in to leave a comment.
Comments
8 comments