DateCalc ( )

Function stats

Average user rating
626
430
9999
Support
FileMaker 10.0 +
Date posted
24 May 2020
Last updated
24 May 2020
Version
Recursive function
No

Author Info
 Nolee

3 functions

Average Rating None

author_avatar



 

Function overview

Prototype

DateCalc  ( start;   years;   months;   days )


Parameters

start  starting date


years  years to add or subtract (or blank)


months  months to add or subtract (or blank)


days  days to add or subtract (or blank)


Description

Tags:  date  

This function will add or subtract months, days, and/or years from the start date. It assumes that if you have a start date with a day number greater than 28 (e.g., 5/31/2020) and you add or subtract to a month with few days (e.g., February), that you want the last day of the month your calculation renders (i.e., 2/29/2020). This will work for any month with fewer total days than the start date. It will then add or subtract any additional days you include in your calculation to the end date for the calculated month.

Examples

Sample input

DateCalc (5/31/2020 ; 0 ; -3 ; 0 )


Sample output

2/29/2020

 

Function code

// This function will add or subtract months, days, and/or years from the start date. It assumes that if you have a start date with a day number greater than 28 (e.g., 5/31/2020) and you add or subtract to a month with few days (e.g., February), that you want the last day of the month your calculation renders (i.e., 2/29/2020). This will work for any month with fewer total days than the start date. It will then add or subtract any additional days you include in your calculation to the end date for the calculated month.

Let ( [

~oldDay = Day ( Start ) ; // the day of the month of the start date
~newMonth = Month ( Start ) + Months ; // the new calculated month
~newLastDay = Day ( Date ( ~newMonth + 1 ; 0 ; Year ( Start ) + years ) ) // the last day of the calculated month (used when the start month has more days than the new calculated month)

] ;

If (

// if the start date has more days than the new calculated month, then use the last day of the new calculated month, plus any days added or subtracted in the calculation; otherwise, directly add or subtract months, days, and years from the start date.

~oldDay > ~newLastDay ; Date ( ~newMonth + 1 ; 0 + days ; Year ( Start ) + years ) ;
Date ( Month ( Start ) + months ; Day ( Start ) + days ; Year ( Start ) + years ) )

)

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

    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/430

    Prototype: DateCalc( start; years; months; days )
    Function Author: Nolee (http://www.fmfunctions.com/mid/626)
    Last updated: 24 May 2020
    Version: 1.3

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

 

 

 

 

 

 

 

Top Tags

Text Parsing  (33)
List  (32)
Date  (30)
XML  (27)
Format  (23)
Sql  (22)
Dev  (20)
Debug  (17)
Layout  (15)
Interface  (15)
Text  (14)
Variables  (13)
Filter  (12)
Design  (11)
Layout Objects  (11)
Array  (8)