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.
now() are not available in the personalization editor for email content. Learn morecurrentTimeInMillis 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.
getCurrentZonedDateTime() instead. Learn morenow(<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.
nowWithDelta(1, "months", "Asia/Tokyo")
When evaluated on 2026-01-31, returns 2026-02-28T…; when evaluated on 2026-05-31, returns 2026-06-30T…
nowWithDelta() uses calendar-month arithmetic. If the target month has fewer days than the current day-of-month, the result is normalized to the last valid day of that month. The function does not roll over into the following month.
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.
This section contains structured knowledge intended to support interpretation, retrieval, and question answering related to this topic.
For complete understanding, this information should be combined with the documentation on this page. Neither source is intended to stand alone; the page describes the feature, while this section provides additional context that helps disambiguate terminology, intent, applicability, and constraints.
- TL;DR: This page documents all date and time functions available in AJO journey expressions, covering how to get the current time, check whether a date falls within a relative time window, and modify date/time components.
Intents:
- Get the current datetime (with optional timezone) using
nowornowWithDelta - Retrieve the current time as an epoch integer using
currentTimeInMillis - Check if a datetime falls within the last N days, hours, months, or years using
inLastDays,inLastHours,inLastMonths,inLastYears - Check if a datetime falls within the next N days, hours, months, or years using
inNextDays,inNextHours,inNextMonths,inNextYears - Force a specific hour or day of the month on a datetime value using
setHoursorsetDays - Convert a datetime to a different timezone while preserving the same instant using
updateTimeZone
Glossary:
- dateTime: A date-time value that includes timezone offset information (product-specific)
- dateTimeOnly: A date-time value with no timezone information (product-specific)
- epoch milliseconds: An integer representing the number of milliseconds elapsed since 1970-01-01T00:00:00Z
- delta: An integer offset (positive or negative) used with
nowWithDeltato shift the current time by a number of years, months, days, hours, minutes, or seconds
Guardrails:
now()is only available in journey expressions; for email personalization usegetCurrentZonedDateTime()instead- The timezone ID in
nowWithDeltamust be a string constant — field references and dynamic expressions are not supported - The timezone ID in
updateTimeZonemust be a string constant
Terminology:
- Canonical name: Date functions — Acronym: none — variants: date-time functions, temporal functions
- Synonyms: “now()” = “current datetime”; “currentTimeInMillis()” = “current epoch milliseconds”
- Do not confuse: “inLastDays” (looks back in time) ≠ “inNextDays” (looks forward in time)
- Do not confuse: “setHours” (replaces the hour component) ≠ “nowWithDelta” (offsets the current time)
- Do not confuse: “updateTimeZone” (same instant, different timezone representation) ≠ “setHours” (changes the time value itself)
FAQ:
- Q: Can I use
now()in email personalization content? — No,now()is only available in journey expressions. UsegetCurrentZonedDateTime()for email personalization. - Q: How do I check if an event happened in the last 24 hours? — Use
inLastHours(@event{MyEvent.timestamp}, 24). - Q: How do I get the current time offset by 2 hours in the past? — Use
nowWithDelta(-2, "hours"). - Q: What does
updateTimeZonedo differently fromsetHours? —updateTimeZonekeeps the same instant in time but expresses it in a different timezone, whilesetHoursactually changes the hour component of the datetime value. - Q: Can the timezone parameter in
nowWithDeltabe a profile field? — No, the timezone ID must be a string constant; field references are not supported. - Q: What happens when
nowWithDelta()is used with months and the current date is a month-end date? — The function uses calendar-month arithmetic and normalizes the result to the last valid day of the target month. For example, adding 1 month to January 31 returns February 28 (not March 3).