About this article
DateAdd() is a function that calculates a date based on another date. It adds days, weeks, months, quarters or years to the selected date.
Prerequisites
|
Syntax 1
Syntax | {{DateAdd (Date, Number, Text)}} |
Input | DateTime, Units, UnitType |
Output | Date with Units added, where Units are UnitType ("d", "M", "Q", "w", "y") |
|
Syntax 2
The syntax below can also be used. If the 'Text' variable is omitted then the Units are interpreted as days.
Syntax | {{DateAdd (Date, Number)}} |
Input | DateTime, Units |
Output | Date with Units added, where Units are Days ("d") |
Example 1
In the examples below 14 days, weeks, months, quarters or years are added to Form.Date.
The value of Form.Date is "1 January 2022".
Description | Binding | Output |
Date + 14 days | {{DateAdd(Form.Date, 14)}} |
2022-01-15 |
Date + 14 days | {{DateAdd(Form.Date, 14, "d")}} |
2022-01-15 |
Date + 14 weeks | {{DateAdd(Form.Date, 14, "w")}} |
2022-04-09 |
Date + 14 months | {{DateAdd(Form.Date, 14, "M")}} |
2023-03-01 |
Date + 14 quarters | {{DateAdd(Form.Date, 14, "Q")}} |
2025-07-01 |
Date + 14 years | {{DateAdd(Form.Date, 14, "y")}} |
2036-01-01 |
Example 2
Using the DateAdd() function in combination with FormatDateTime() to apply formatting to the output.
The value of Form.Date is "1 January 2022".
Description | Binding | Output |
Date + 14 days | {{FormatDateTime(DateAdd(Form.Date, 14, "d"), "d MMMM yyyy", "en-US")}} |
15 January 2022 |
Example 3
Using the DateAdd() function in combination with StringJoin() and FormatDateTime() to show a start and end date, separated by a '-'.
Binding | {{StringJoin(" - ", FormatDateTime(Form.Date, "d MMMM yyyy", "en-US"), FormatDateTime(DateAdd(Form.Date, 1, "M"), "d MMMM yyyy", "en-US"))}} | |
Input | Form.Date = "1 January 2022" | Form.Date = "" |
Output | 1 January 2022 - 1 February 2022 | Empty |
Example 4
Using the DateAdd() function in combination with FormatDateTime() and DateValue() to show the date + 14 days as output, when the source is a HostSystem field and the formatting is 'day-month-year hours:minutes'.
Binding | {{FormatDateTime(DateAdd(DateValue(HostSystem.Date, "d-M-yyyy H:m", "nl-NL"), 14, "d"), "d MMMM yyyy")}} |
Input | HostSystem date = "3-8-2020 4:30" |
Output | "17 augustus 2020" |
|
Related articles
Comments
0 comments
Article is closed for comments.