Function overview
Prototype
CalculateEndDate (
startDate; days; wkEnds )
Parameters
startDate DATE
days NUMBER
wkEnds BOOLEAN
Description
Tags:
Weekends Weekend Range Date Business Days
Calculates the end of a date range, given the start date and the number of days in the range.
Allows to specify only whether weekends are included in the day count. In other words, if wkEnds = FALSE, then it will assume that the day count is "business days," and not "calendar days". It will then add the correct number of days to account for the weekends.
There are several custom functions "out there" that do this same thing, and some even exclude holidays also. However, all the ones I could find use recursion and are significantly slower than this one, because: This just uses Math, not recursion, and is therefore much faster, especially for larger day ranges.
Examples
Sample input
CalculateEndDate ( '6/4/2010' ; 8 ; 0 )
Sample output
6/15/2010
Function code
Let ([
/* These first three are for testing.
* To use them, copy this function body into the Data Viewer,
* uncomment these, and then fiddle with their values as the inputs.
wkEnds = 0
; days = 7
; startDate = date ( 6; 9 ; 2010 )
;*/ gridDays = days - ( 7 - DayOfWeek ( startDate ) + 1 ) + 1
; extras = days - gridDays
; padGrid = ( Div ( gridDays ; 5 ) + ( extras < 5 ) ) * 2
; calDays = startDate + days - 1
; output = calDays + (not wkEnds) * padGrid * (extras < days)
];
output
)
// ===================================
/*
This function is published on FileMaker Custom Functions
to check for updates and provide feedback and bug reports
please visit http://www.fmfunctions.com/fid/258
Prototype: CalculateEndDate( startDate; days; wkEnds )
Function Author: Steve Allen (http://www.fmfunctions.com/mid/148)
Last updated: 10 June 2010
Version: 1
*/
// ===================================
Let ([__LITBR__/* These first three are for testing.__LITBR__ * To use them, copy this function body into the Data Viewer,__LITBR__ * uncomment these, and then fiddle with their values as the inputs.__LITBR____LITBR____LITBR__ wkEnds = 0__LITBR__; days = 7__LITBR__; startDate = date ( 6; 9 ; 2010 )__LITBR__;*/ gridDays = days - ( 7 - DayOfWeek ( startDate ) + 1 ) + 1__LITBR__; extras = days - gridDays__LITBR__; padGrid = ( Div ( gridDays ; 5 ) + ( extras < 5 ) ) * 2__LITBR__; calDays = startDate + days - 1__LITBR__; output = calDays + (not wkEnds) * padGrid * (extras < days)__LITBR__];__LITBR__ output__LITBR__)__LITBR____LITBR__// ===================================__LITBR__/*__LITBR____LITBR__ This function is published on FileMaker Custom Functions__LITBR__ to check for updates and provide feedback and bug reports__LITBR__ please visit http://www.fmfunctions.com/fid/258__LITBR____LITBR__ Prototype: CalculateEndDate( startDate; days; wkEnds )__LITBR__ Function Author: Steve Allen (http://www.fmfunctions.com/mid/148)__LITBR__ Last updated: 10 June 2010__LITBR__ Version: 1__LITBR____LITBR__*/__LITBR__// ===================================
Login or register to comment
Create a new account with fmcustomfunctions.com or login to post a comment.