5 Replies Latest reply on Oct 20, 2015 1:52 PM by erolst

# How do I create a calculation that gives me the number of business days between two dates?

Trying to create a calculation that gives me the number of business days that have passed between two date fields. Basically removing weekends and holidays.

• ###### 1. Re: How do I create a calculation that gives me the number of business days between two dates?

Hi. If you have FIleMaker Pro Advanced, you can create a custom function. This here, will do what you need.

FileMaker Custom Function:BusinessDays ( startDate ; endDate )

it needs this function as well: FileMaker Custom Function:BusinessHolidays ( calendarYear ) to run together.

It looks daunting but I've used it and it works nicely. You simply create the parameters in that section to match these then copy this code into the custom-function editor.

• ###### 2. Re: How do I create a calculation that gives me the number of business days between two dates?

Not using Filemaker Advanced. Is there anything I can do otherwise?

• ###### 3. Re: How do I create a calculation that gives me the number of business days between two dates?

If a Custom Function is non-recursive, you don't necessarily need FM Advanced to use its logic – provided the CF is non-recursive.

Here is such a non-recursive CF, courtesy of user19752:

// CountWeekdays_user19752 ( From ; To )

Case (

To >= From ;

Let ( [

Fsun = From - DayOfWeek ( From ) + 1 ;

Nsat = Div ( To - Fsun + 1 ; 7 ) ;

Fmon = From - Mod ( DayOfWeek ( From ) + 5 ; 7 ) ;

Nsun = Div ( To - Fmon + 1 ; 7 )

] ;

To - From + 1 - Nsat - Nsun

)

)

Use it in a calculation field with this little modification (replacing function arguments with direct field references):

Let ( [

From = yourStartDateField ;

To = yourEndDateField

] ;

Case (

To >= From ;

Let ( [

Fsun = From - DayOfWeek ( From ) + 1 ;

Nsat = Div ( To - Fsun + 1 ; 7 ) ;

Fmon = From - Mod ( DayOfWeek ( From ) + 5 ; 7 ) ;

Nsun = Div ( To - Fmon + 1 ; 7 )

] ;

To - From + 1 - Nsat - Nsun

)

)

)