DateAdd
→ stringAdds a specified number of intervals (days, months, hours, etc.) to a date value.
Available in:
Email
CloudPage
Automation
Triggered Send
Syntax
Platform.Function.DateAdd(date, interval, datePart)
3 arguments
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
date |
string | Yes | Date value to modify |
interval |
number | Yes | Number of intervals to add (can be negative to subtract) |
datePart |
string | Yes | Unit for the interval |
DatePart Values
| Value | Meaning |
|---|---|
"Y" |
Years |
"M" |
Months |
"D" |
Days |
"H" |
Hours |
"MI" |
Minutes |
"S" |
Seconds |
Examples
var now = Platform.Function.Now();
// Add 30 days
var in30Days = Platform.Function.DateAdd(now, 30, "D");
// Subtract 1 year
var lastYear = Platform.Function.DateAdd(now, -1, "Y");
// Add 2 hours
var twoHoursLater = Platform.Function.DateAdd(now, 2, "H");
// Set cookie expiry to 15 minutes from now
var expiry = Platform.Function.DateAdd(now, 15, "MI");
var expiryStr = Platform.Function.FormatDate(expiry, "M/D/YYYY H:MM:SS");
Platform.Response.SetCookie("session", token, expiryStr, true);