Date interval calculations help!

Hi all,

I have a process where I need to calculate the number of full clear working days between two fields, but the ‘interval between two fields (working days)’ seems to subtract days in certain circumstances.

For example, if I raise the request on a Monday, for an event on the following Saturday, it calculates there are 3 full working days, instead of the correct 4 full working days (Tues, Weds, Thurs, Fri) between the dates.

I understand it doesn’t count the partial Monday (which I don’t want it to anyway), but how is it calculating 3 workings days from the above?

Am I missing something here?

If i remember correctly, I am sure the count starts as “0”, so its calculating, Tues = 0, Wed = 1, Thurs = 2, Fri = 3.

1 Like

Ah ok, thank you that makes slightly more sense as to how it is displaying 3.

It still rather leaves me unable to solve my issue though.

I need to calculate a number of full working days between two dates, not inclusive of the dates either side, which the system seems to be unable to distinguish.

Can anyone suggest how I go about this?

You will likely need to add some code studio to your build to work out what you need exactly, something similar to below:

//Function to calculate working days between Two Dates
function calculate_working_days (fromdate, todate){
        var i = 1;
        while (fromdate < todate ){
            if ( mats.​is_working_day( fromdate.toString().substring(0, 24)  ) ) {
                i++;
            }
            if (i > 1000){
                return 1000; // limit on count in case of a bug
            }
            fromdate.setDate( fromdate.getDate() + 1 )
        }
        return i;
}
2 Likes

Hi Jo, two other points to consider. 1. Does this function need to factor in public holidays? 2. What would constitute a NOT full working day and how would the function take that into consideration?

Cheers - MP

Hi, I think the composite function produces seemingly strange results if the fields have a time element to them. Are the two fields you are using Date and Time fields?
If so try creating some Date only fields (either composites of the Date Time fields that only return the date portion, or completely separate properties), and try using those in the original Composite and you may get a different result.
I believe it should discount the start date but include the end date.