Date & Time Arithmetic

Use this reference when performing date and time arithmetic in your flows. For example:
To add or subtract seconds, minutes, hours, days, months, or years from a given date, use @datetime_add:
@(datetime_add("2017-01-15", 5, "D"))
adds 5 days@(datetime_add(fields.dob, -3, "M"))
subtracts 3 months
To compose a datetime from a known date/time and a separate hour, e.g.:
Your next appointment is at @(replace_time(contact.created_on, time("15:00")))
To adjust the time of an existing datetime, use @datetime_add, for example:
15 hours from now is @(datetime_add(contact.created_on, 15, "h"))
To overwrite the time component of any datetime, use @replace_time:
@(replace_time(now(), "10:30"))
returns today at 10:30 a.m.
To calculate a duration between date1
and date2
in a specified unit, use:
@datetime_diff(date1, date2, unit)
Valid units are: "Y"
(years), "M"
(months), "W"
(weeks), "D"
(days), "h"
(hours), "m"
(minutes), "s"
(seconds).
Examples:
@(datetime_diff("2017-01-15", "2017-01-17", "D"))
→2
@(datetime_diff("2017-01-15", "2017-05-15", "W"))
→17
@(datetime_diff("2017-01-15", "2017-05-15", "M"))
→4
@(datetime_diff("2017-01-17 10:50", "2017-01-17 12:30", "h"))
→1
@(datetime_diff("2017-01-17", "2015-12-17", "Y"))
→-2
For a more comprehensive function reference, see the full list of functions here.