CalculateEndDate ( startDate ; days ; wkEnds )
Calculate End Date given Start Date and number of days, inclusive; handles weekends. NOT Recursive.
Average rating: 3.8 (46 votes) Log in to vote
Steve Allen Richard Carlton Consulting, Inc. http://www.rcconsulting.com |
Function definition: (Copy & paste into FileMaker's Edit Custom Function window)
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.
Comments
PANOS, CREECE Jun 10, 2010 |
||
wkEnds fields, what type must to be? and what includes? When i put (0) zero then functions count correctly, but when put 1 for a holidays day, then does not work |
||
Jeffrey E. Bloch, Fairfield, CT Feb 15, 2011 |
||
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 |
||
Steve, Lancaster Feb 15, 2011 |
||
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 |
||
Daniel Wood, Digital Fusion Ltd Apr 21, 2011 |
||
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. |
||
Chris Wessels, Sydney, Australia Jan 25, 2012 |
||
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 ) |
||
dansmith65, BC, Canada Jun 2, 2016 |
||
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 |
||
Joshua Paul, Neo Code May 7, 2018 |
||
The original function is not useful. But Chris Wessels function is good. VERY GOOD: 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 ) |
||
Note: these functions are not guaranteed or supported by BrianDunning.com. Please contact the individual developer with any questions or problems.