Date calculations: Increment a date by a certain number of days, months or years.
First, some simple examples:
Add 25 years to the value in the data element ‘DateOfBirth’: «IncrementDate(DateOfBirth,25, "y")»
Insert tomorrow’s date into the document: «IncrementDate(Today(),1,"d")»
i.e. add 1 day to today’s date.
Insert yesterday’s date into the document: «IncrementDate(Today(),-1,"d")»
i.e. subtract 1 day from today’s date.
Now format those incremented dates:
Yesterday’s date: «FormatDate(IncrementDate(Today(),-1,’d’),’MMMMM d yyyy’)»
The matter was closed 6 months ago on «FormatDate(IncrementDate(Today(),-6, "m"),"d MMMM yyyy")»
.
Working Days:
The “w” option means “working days”, not to be confused with “weeks”.
Saturdays and Sundays are always considered non-working days. For example, if two working days are added to a date which is a Friday, then the result is the following Tuesday.
Extra non-working days can be added either by specifying them in the function call itself, or by configuring them in the “Other Settings” tab of the XpressDox configuration. For example:
The court appearance will be in 10 court days from now, i.e. «FormatDate(IncrementDate(Today(),10,'w','2024-01-01,2024-05-01,2024-12-25'),'MMMM d, yyyy')»
.
If the non-working days are omitted from the function call («FormatDate(IncrementDate(Today(),10,'w'),'MMMM d, yyyy')»
) then the non-working days are taken from the XpressDox configuration, if they have been specified and apply to the template being executed. In any case, Saturdays and Sundays are always regarded as non-working days.
The non-working day dates provided in the function call do not need to be hard-coded. For example, if there is another system available at the site where the template is run and this system maintains a reliable list of non-working days, and this system is accessible via COM or .NET, then using the XpressDox Interact with External Programs capability, the following would be possible:
The court appearance will be in 10 court days from now, i.e. «FormatDate(IncrementDate(Today(),10,'w',GetObjectValue('o2Smart.Accounting:Settings.GetPublicHolidays')),'MMMM d, yyyy')»
.
Further examples:
Example 1: Calculate either days or months from today «ChooseFromRDBList(Time_period,Weekly,Monthly)» «Today('D MMMM, yyyy')» incremented «Time_period» «if(Time_period = 'Weekly')» «FormatDate(IncrementDate(Today(),7,'d'),'d MMMM, yyyy')» «Else()» «FormatDate(IncrementDate(Today(),1,'m'),'d MMMM, yyyy')» «End()»
Example 2: Calculate a number of days from a given date Beginning date of hearing: «FormatDate(Hearing_Date,'d MMMM yyyy')» Length of hearing (working days): «No_of_days» Calculated end date: «FormatDate(IncrementDate(Hearing_Date,No_of_days,'w'),’d MMMM yyyy’)»
Example 3: Calculate two weeks from a given date Rental contract: Effective date of contract: «FormatDate(Effective_date,'d MMMM, yyyy')» Period in months: «Period» Rental commences on: «SetVr('rentStart',IncrementDate(Effective_date,Period,'m'))» «FormatDate(GetV('rentStart'),'d MMMM, yyyy')» Two weeks after rent becomes effective: «FormatDate(IncrementDate(GetV('rentStart'),14,'d'),'d MMMM, yyyy')» Day before rental is due landlord should inspect property: «FormatDate(IncrementDate(GetV('rentStart'),-1,'d'),'D MMMM, yyyy')»