Date functions date-functions
Date functions enable you to manipulate and work with date and time values within your journey expressions. These functions are essential for time-based conditions, scheduling, and temporal calculations in your customer journeys.
Use date functions when you need to:
- Get the current time or date with specific timezone handling (now, nowWithDelta, currentTimeInMillis)
- Check if a date falls within a specific time range (inLastDays, inLastHours, inLastMonths, inLastYears, inNextDays, inNextHours, inNextMonths, inNextYears)
- Modify date and time components (setHours, setDays, updateTimeZone)
- Perform time-based calculations and comparisons
- Convert between different time formats and representations
Date functions provide precise control over temporal logic, allowing you to create time-sensitive journey paths and conditions that respond to specific timeframes and schedules.
currentTimeInMillis currentTimeInMillis
Returns current time in epoch milliseconds.
currentTimeInMillis()currentTimeInMillis()
Returns an integer.
currentTimeInMillis()
Returns ā1544712617131ā.
inLastDays inLastDays
Returns true if a given dateTime is between now and now - delta days.
inLastDays(<dateTime>,<delta>)| table 0-row-2 1-row-2 2-row-2 | |
|---|---|
| Parameter | Type |
| date time | dateTime |
| delta | integer |
inLastDays(<dateTime>,<integer>)
Returns a boolean.
inLastDays(toDateTime('2023-12-12T01:11:00Z'), 4)
Returns true.
inLastHours inLastHours
Returns true if the given date time is between now and now - delta hours.
inLastHours(<dateTime>,<delta>)| table 0-row-2 1-row-2 2-row-2 | |
|---|---|
| Parameter | Type |
| date time | dateTime |
| delta | integer |
inLastHours(<dateTime>,<integer>)
Returns a boolean.
inLastHours(toDateTime('2023-12-12T01:11:00Z'), 4)
Returns true.
inLastHours(@event{MyEvent.timestamp}, 4)
Returns true.
inLastMonths inLastMonths
Returns true if a given date or dateTime is between now and now - delta months.
inLastMonths(<dateTime>,<delta>)| table 0-row-2 1-row-2 2-row-2 | |
|---|---|
| Parameter | Type |
| date time | dateTime |
| delta | integer |
inLastMonths(<dateTime>,<integer>)
Returns a boolean.
inLastMonths(toDateTime('2023-12-12T01:11:00Z'), 4)
Returns true.
inLastYears inLastYears
Returns true if a given date or dateTime is between now and now - delta years.
inLastYears(<dateTime>,<delta>)| table 0-row-2 1-row-2 2-row-2 | |
|---|---|
| Parameter | Type |
| date time | dateTime |
| delta | integer |
inLastYears(<dateTime>,<integer>)
Returns a boolean.
inLastYears(toDateTime('2023-12-12T01:11:00Z'), 4)
Returns true.
inNextDays inNextDays
Returns true if a given date or dateTime is between now and now + delta days.
inNextDays(<dateTime>,<delta>)| table 0-row-2 1-row-2 2-row-2 | |
|---|---|
| Parameter | Type |
| date time | dateTime |
| delta | integer |
inNextDays(<dateTime>,<integer>)
Returns a boolean.
inNextDays(toDateTime('2023-12-12T01:11:00Z'), 4)
Returns true.
inNextHours inNextHours
Returns true if a given date or dateTime is between now and now + delta hours.
inNextHours(<dateTime>,<delta>)| table 0-row-2 1-row-2 2-row-2 | |
|---|---|
| Parameter | Type |
| date time | dateTime |
| delta | integer |
inNextHours(<dateTime>,<integer>)
Returns a boolean.
inNextHours(toDateTime('2023-12-12T01:11:00Z'), 4)
Returns true.
inNextMonths inNextMonths
Returns true if a given date or dateTime is between now and now + delta months.
inNextMonths(<dateTime>,<delta>)| table 0-row-2 1-row-2 2-row-2 | |
|---|---|
| Parameter | Type |
| date time | dateTime |
| delta | integer |
inNextMonths(<dateTime>,<integer>)
Returns a boolean.
inNextMonths(toDateTime('2023-01-12T01:11:00Z'), 4)
Returns true.
inNextYears inNextYears
Returns true if a given date or dateTime is between now and now + delta years.
inNextYears(<dateTime>,<delta>)| table 0-row-2 1-row-2 2-row-2 | |
|---|---|
| Parameter | Type |
| date time | dateTime |
| delta | integer |
inNextYears(<dateTime>,<integer>)
Returns a boolean.
inNextYears(toDateTime('2021-12-12T01:11:00Z'), 4)
Returns true.
now now
Returns the current date in date time format. For more information on data types, refer to this page.
now(<parameter>)| table 0-row-2 1-row-2 | |
|---|---|
| Parameter | Description |
| string | Time zone identifier (optional) |
now()
now("<timeZone id>")
Returns a dateTime.
now()
Returns 2023-06-03T06:30Z.
toString(now())
Returns ā2023-06-03T06:30Zā
now("Europe/Paris")
Returns 2023-06-03T08:30+02:00.
nowWithDelta nowWithDelta
Returns the current datetime including an offset. If a time zone id is specified, the time zone offset will be applied. For more information on data types, refer to this page.
nowWithDelta(<parameters>)| table 0-row-2 1-row-2 2-row-2 3-row-2 | |
|---|---|
| Parameter | Description |
| delta | positive or negative integer value |
| date part | years, months, days, hours, minutes or seconds as a string |
| time zone id | string representation of the time zone value. For more, see Data types. Time zone id must be a string constant. It cannot be a field reference nor an expression. |
nowWithDelta(<delta>,<date part>
nowWithDelta(<delta>,<date part>,"<timeZone id>")
Returns a dateTime.
nowWithDelta(-2, "hours")
nowWithDelta(-2, "hours", "Europe/Paris")
Returns a dateTime exactly 2 hours ago.
setHours setHours
Sets the hours of a date time or date time only. For example, if you want to wait until a certain hour tomorrow, you can force the hour.
setHours(<parameter>)| table 0-row-2 1-row-2 2-row-2 3-row-2 | |
|---|---|
| Parameter | Type |
| date time | dateTime |
| date time without considering time zone | dateTimeOnly |
| hours | integer |
setHours(<dateTime>,<hours>)
Returns a datetime.
setHours(<dateTimeOnly>,<hours>)
Returns a datetime without considering time zone.
setHours(toDateTime('2023-12-12T01:11:00Z'), 4)
Returns 2023-12-12T04:11:00Z.
setHours(nowWithDelta(1, "days"), 20)
Returns tomorrow at 8:XY PM, XY being the minutes at the moment of the current time evaluation. If the evaluation happens at 2:45 AM, the returned time will be 8:45 PM.
setDays setDays
Sets the day of a date time or date time only. For example, if you want to wait until a certain day of the month, you can force the day.
setDays(<parameter>)| table 0-row-2 1-row-2 2-row-2 3-row-2 | |
|---|---|
| Parameter | Type |
| date time | dateTime |
| date time without considering time zone | dateTimeOnly |
| days | integer |
setDays(<dateTime>,<days>)
Returns a datetime.
setDays(<dateTimeOnly>,<days>)
Returns a datetime without considering time zone.
setDays(toDateTime('2023-12-12T01:11:00Z'), 25)
Returns 2023-12-25T01:11:00Z.
setDays(toDateTimeOnly(@event{MyEvent.registrationDate}), 1)
updateTimeZone updateTimeZone
Returns a new date time, with a new time zone on the same instant.
updateTimeZone(<parameters>)- time zone id: string
- dateTime
updateTimeZone(<dateTime>,<timeZone id>)
Returns a datetime.
updateTimeZone( toDateTime("2023-08-28T08:15:30.123-07:00"), "Europe/Paris"))
Returns 2023-08-28T17:15:30.123+02:00.
updateTimeZone(@event{MyExpEvent.timestamp}, "Australia/Sydney")
If the value of the timestamp field is 2021-11-16T16:55:12.939318+01:00, then the function returns 2021-11-17T02:55:12.942115+11:00.