calculate business days

Answered

Comments

8 comments

  • Rainer Grabowski (FVM)

    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 formatterm 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 brackets

    Cheers,
    Rainer

    1
    Comment actions Permalink
  • Rahil Pirani

    hi @Rainer -- Thank you for your quick help and response! Quick question... would the calculated field be a date field automatically, or do I need to set it as such?

    0
    Comment actions Permalink
  • Rainer Grabowski (FVM)

    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).

    0
    Comment actions Permalink
  • Alain Müller

    Hi Rahil, I have the same problem... A Question to Rainer: How dos the transfer with Globiflow work? I just signed up with Globiflow, but I can't see how i can "creat" this transfer. Can you tell me how this works? Thanks Alain

    0
    Comment actions Permalink
  • Rainer Grabowski (FVM)

    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] = calc date ("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).

    0
    Comment actions Permalink
  • David Gélinas

    How would you go about calculating the difference in business days between two dates (@End - @Beginning)

    0
    Comment actions Permalink
  • Rainer Grabowski (FVM)

    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-us

    Rainer

    0
    Comment actions Permalink
  • Podio CAD

    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

    0
    Comment actions Permalink

Please sign in to leave a comment.

Powered by Zendesk