51黑料不打烊

Journey optimizer date functions

Journey Optimizer provides a variety of functions centered around date and time manipulations, making it easier to handle time-based operations. These functions are useful for scenarios where you need to calculate time differences, set specific time values, or adjust time zones within your customer journeys.

Example usage

Suppose you want to send a notification to a user if they have interacted with your service within the last 3 days. You can utilize the inLastDays function in your journey as follows:

if (inLastDays(@event{userInteraction.timestamp}, 3)) {
  // Send notification
}

This example checks if the user鈥檚 last interaction occurred within the last three days and triggers a notification accordingly.

Function details

Function Name
Description
Syntax
Parameters
Returns
Example
currentTimeInMillis
Returns the current time in epoch milliseconds.
currentTimeInMillis()
None
integer
currentTimeInMillis()
// Returns 鈥1544712617131鈥
inLastDays
Checks if a date is within the last specified number of days.
inLastDays(<dateTime>,<delta>)
dateTime: date
delta: integer
boolean
inLastDays(toDateTime('2023-12-12T01:11:00Z'), 4)
// Returns true
inLastHours
Checks if a date/time is within the last specified number of hours.
inLastHours(<dateTime>,<delta>)
dateTime: date
delta: integer
boolean
inLastHours(toDateTime('2023-12-12T01:11:00Z'), 4)
// Returns true
inLastMonths
Checks if a date is within the last specified number of months.
inLastMonths(<dateTime>,<delta>)
dateTime: date
delta: integer
boolean
inLastMonths(toDateTime('2023-12-12T01:11:00Z'), 4)
// Returns true
inLastYears
Checks if a date is within the last specified number of years.
inLastYears(<dateTime>,<delta>)
dateTime: date
delta: integer
boolean
inLastYears(toDateTime('2023-12-12T01:11:00Z'), 4)
// Returns true
inNextDays
Checks if a date is within the next specified number of days.
inNextDays(<dateTime>,<delta>)
dateTime: date
delta: integer
boolean
inNextDays(toDateTime('2023-12-12T01:11:00Z'), 4)
// Returns true
inNextHours
Checks if a date/time is within the next specified number of hours.
inNextHours(<dateTime>,<delta>)
dateTime: date
delta: integer
boolean
inNextHours(toDateTime('2023-12-12T01:11:00Z'), 4)
// Returns true
inNextMonths
Checks if a date is within the next specified number of months.
inNextMonths(<dateTime>,<delta>)
dateTime: date
delta: integer
boolean
inNextMonths(toDateTime('2023-01-12T01:11:00Z'), 4)
// Returns true
inNextYears
Checks if a date is within the next specified number of years.
inNextYears(<dateTime>,<delta>)
dateTime: date
delta: integer
boolean
inNextYears(toDateTime('2021-12-12T01:11:00Z'), 4)
// Returns true
now
Provides the current date and time.
now(<parameter>)
string
dateTime
now()
// Returns 2023-06-03T06:30Z
now("Europe/Paris")
// Returns 2023-06-03T08:30+02:00
nowWithDelta
Gives the current date/time with an added offset.
nowWithDelta(<delta>, <date_part>, <time zone id>)
delta:听颈苍迟别驳别谤
date_part:听蝉迟谤颈苍驳
time zone id: optional string
dateTime
nowWithDelta(-2, "hours")
// Returns 2 hours ago
nowWithDelta(-2, "hours", "Europe/Paris")
setHours
Sets the hours for a date/time.
setHours(<dateTime>, <hours>)
dateTime: date
hours: integer
- dateTime
- dateTimeOnly
setHours(toDateTime('2023-12-12T01:11:00Z'), 4)
// Returns 2023-12-12T04:11:00Z
setDays
Sets the day for a date/time.
setDays(<dateTime>, <days>)
dateTime: date
days: integer
- dateTime
-听dateTimeOnly
setDays(toDateTime('2023-12-12T01:11:00Z'), 25)
// Returns 2023-12-25T01:11:00Z
updateTimeZone
Changes the time zone of a given date/time.
updateTimeZone(<timeZone id>, <dateTime>)
timeZone id: string
dateTime: date
dateTime
updateTimeZone(toDateTime("2023-08-28T08:15:30.123-07:00"), "Europe/Paris")
// Returns 2023-08-28T17:15:30.123+02:00
recommendation-more-help
91a6d90a-6d61-4a62-bbed-ae105e36a860