Shopping Cart

Search:

Signup

Contact

FileMaker is a registered trademark of FileMaker, Inc. in the U.S. and other countries.

# FileMaker Pro Custom Functions

CalculateEndDate ( startDate ; days ; wkEnds )

Rate this function:

Average rating: 3.9  (44 votes)
Discuss this Custom Function

Steve Allen, Richard Carlton Consulting, Inc.
http://www.rcconsulting.com

Calculate End Date given Start Date and number of days, inclusive; handles weekends. NOT Recursive.

Sample Input:
 CalculateEndDate ( '6/4/2010' ; 8 ; 0 )
Sample Output:
 6/15/2010

Then copy & paste into FileMaker Advanced's Edit Custom Function window.

## Description:

Allows to calculate the end of a date range, given the start of the range, and the number of days in the range.

Has a parameter for weekends. Specifying TRUE is saying "the number of days specified includes weekends", and therefore returns the calendar day range (equivalent to Start + Days - 1).

Specifying FALSE for the weekends parameter is saying "the number of days specified does NOT include weekends -- it's only business days," and so to get the correct end date, it adds the weekends in.

There are several function "out there" that do this, but this is the only one I know of that does it using Math, not recursion. In my experience with the others, this one is much faster, especially on long ranges.

Note: these functions are not guaranteed or supported by BrianDunning.com. Please contact the individual developer with any questions or problems.

This is my Custom Function and I want to edit it

## Discuss:

5 most recent comments | Show all 6 comments

Richard,

What if you need to subtract multiple months from a date, maintaining the same "day" (ie. 15th of the month)? This seems complex since some months have more days than others.

Thanks!!

jeff@theccsgroup.net

Jeffrey E. Bloch, Fairfield, CT
February 15, 2011 3:38pm

Jeff,

The built-in Date function will allow you to do that.

Just use:

Date (
Month ( mydate ) - number_of_months_to_subtract
; Day ( mydate )
; Year ( mydate )
)

FileMaker will take care of the rest.

Thanks,

Steve Allen

Steve, Fairfield, CA
February 15, 2011 3:41pm

Hi Steven, I've found an issue with this function but not sure how to resolve it. I was trying to use it to calculate the end date after X working days excluding weekends:

Start Date = 25/7/2011 (25 July)
Days: 26
Exclude weekends

The function gives me an end date of 27/8/2011 , which is actually a saturday. The result I would expect is 29th of August which is the monday.

I have checked this manually and the final day after 26 is definitely the 29th. The function is beyond me in terms of figuring out how to fix it sorry.

Daniel Wood, New Zealand
April 21, 2011 6:02pm

I, like Daniel found a problem with this. I came up with the following, which seems to be working nicely:

Note: Unlike Steven's original function, this one always excludes week ends....

Let ([
/* Calculates startDate + days excluding week ends */
day = If(DayOfWeek(startDate)=1;7;DayOfWeek(startDate)-1)
; output = startDate + days + If(day = 6; 2 ; 0) +
(Floor ( ( days -1 + ( If(day=6;1; Mod ( day ; 6 )^1 ) ) ) /5 ) *2 )

];
output
)

Chris Wessels, Sydney, Australia
January 25, 2012 10:05pm

With Chris's version, an input date of date ( 5 ; 28 ; 2016 ), I expected Date ( 6 ; 10 ; 2016 ), but got Date ( 6 ; 13 ; 2016 ).

It may be an edge case, but it seems like a date starting on the weekend produces unexpected results. I ended up using CompletionDate by Daniele Raybaudi: http://www.fmfunctions.com/functions_display_record.php?functionId=338

June 02, 2016 5:34pm

Make a comment about this Custom Function (please try to keep it brief & to the point). Anyone can post:

 Your Name: City/Location: Comment: characters left. If you paste in more than 1500 characters, it will be truncated. Discuss the function - advertisements and other useless posts will be deleted. Answer 7 + 4 =
 Search for Custom Functions:

 Download the Custom Function Dashboard Widget for OS X Keep all the latest Custom Functions right at your fingertips!