CalculateEndDate ( )

Function stats

Average user rating
148
258
9999
Support
FileMaker 7.0 +
Date posted
10 June 2010
Version
1
Recursive function
No

Author Info
 Steve Allen

15 functions

Average Rating 5.0

author_avatar



 

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

*/
// ===================================

 

 

 

 

 

 

 

Top Tags

Text Parsing  (33)
List  (31)
Date  (28)
XML  (26)
Format  (23)
Sql  (22)
Dev  (20)
Debug  (17)
Layout  (15)
Interface  (15)
Text  (14)
Variables  (12)
Filter  (11)
Layout Objects  (11)
Design  (10)
Array  (7)