Date and time functions are used to perform date and time operations on values within Journey Optimizer.
The addDays
function adjusts a given date by a specified number of days, using positive values to increment and negative values to decrement.
Syntax
{%= addDays(date, number) %}
{%= addDays(stringToDate("2024-11-01T17:19:51Z"),10) %}
2024-11-11T17:19:51Z
The addHours
function adjusts a given date by a specified number of hours, using positive values to increment and negative values to decrement.
Syntax
{%= addHours(date, number) %}
{%= addHours(stringToDate("2024-11-01T17:19:51Z"),1) %}
2024-11-01T18:19:51Z
The addMinutes
function adjusts a given date by a specified number of minutes, using positive values to increment and negative values to decrement
Syntax
{%= addMinutes(date, number) %}
{%= addMinutes(stringToDate("2024-11-01T17:59:51Z"),10) %}
2024-11-01T18:09:51Z
The addMonths
function adjusts a given date by a specified number of months, using positive values to increment and negative values to decrement.
Syntax
{%= addMonths(date, number) %}
{%= addMonths(stringToDate("2024-11-01T17:19:51Z"),2) %}
2025-01-01T17:19:51Z
The addSeconds
adjusts a given date by a specified number of seconds, using positive values to increment and negative values to decrement.
Syntax
{%= addSeconds(date, number) %}
{%= addSeconds(stringToDate("2024-11-01T17:19:51Z"),10) %}
2024-11-01T17:20:01Z
The addYears
adjusts a given date by a specified number of years, using positive values to increment and negative values to decrement.
Syntax
{%= addYears(date, number) %}
{%= addYears(stringToDate("2024-11-01T17:19:51Z"),2) %}
2026-11-01T17:19:51Z
The age
function is used to retrieve the age from a given date.
Syntax
{%= age(datetime) %}
The ageInDays
function calculates the age of a given date in days, i.e. the number of days elapsed between the given date and the current date, negative for future dates and positive for past dates.
Syntax
{%= ageInDays(date) %}
currentDate = 2025-01-07T12:17:10.720122+05:30 (Asia/Kolkata)
{%= ageInDays(stringToDate("2025-01-01T17:19:51Z"))%}
5
The ageInMonths
function calculates the age of a given date in months, i.e. the number of months elapsed between the given date and the current date , negative for future dates and positive for past dates.
Syntax
{%= ageInMonths(date) %}
currentDate = 2025-01-07T12:22:46.993748+05:30(Asia/Kolkata)
{%=ageInMonths(stringToDate("2024-01-01T00:00:00Z"))%}
12
The compareDates
function compares the first input date with the other. Returns 0 if date1 is equal to date2, -1 if date1 comes before date2 and 1 if date1 comes after date2.
Syntax
{%= compareDates(date1, date2) %}
{%=compareDates(stringToDate("2024-12-02T00:00:00Z"), stringToDate("2024-12-03T00:00:00Z"))%}
-1
The convertZonedDateTime
function converts a date-time to a given timezone.
Syntax
{%= convertZonedDateTime(dateTime, timezone) %}
{%=convertZonedDateTime(stringToDate("2019-02-19T08:09:00Z"), "Asia/Tehran")%}
2019-02-19T11:39+03:30[Asia/Tehran]
The currentTimeInMillis
function is used to retrieve current time in epoch milliseconds.
Syntax
{%= currentTimeInMillis() %}
The dateDiff
function is used to retrieve the difference between two dates in number of days.
Syntax
{%= dateDiff(datetime,datetime) %}
The dayOfWeek
returns the number representing the day of the month.
Syntax
{%= dayOfMonth(datetime) %}
{%= dayOfMonth(stringToDate("2024-11-05T17:19:51Z")) %}
5
The dayOfWeek
function is used to retrieve the day of week.
Syntax
{%= dayOfWeek(datetime) %}
The dayOfYear
function is used to retrieve the day of year.
Syntax
{%= dayOfYear(datetime) %}
The diffInSeconds
function returns the difference between two dates in terms of seconds.
Syntax
{%= diffInSeconds(endDate, startDate) %}
{%=diffInSeconds(stringToDate("2024-11-01T17:19:51Z"), stringToDate("2024-11-01T17:19:01Z"))%}
50
The extractHours
function extracts the hour component from a given timestamp.
Syntax
{%= extractHours(date) %}
{%= extractHours(stringToDate("2024-11-01T17:19:51Z"))%}
17
The extractMinutes
function extracts the minute component from a given timestamp.
Syntax
{%= extractMinutes(date) %}
{%= extractMinute(stringToDate("2024-11-01T17:19:51Z"))%}
19
The extractMonth
function extracts the month component from a given timestamp.
Syntax
{%= extractMonths(date) %}
{%=extractMonth(stringToDate("2024-11-01T17:19:51Z"))%}
11
The extractSeconds
function extracts the second component from a given timestamp.
Syntax
{%= extractSeconds(date) %}
{%=extractSeconds(stringToDate("2024-11-01T17:19:51Z"))%}
51
The formatDate
function is used to format a date time value. The format should be a valid Java DateTimeFormat pattern.
Syntax
{%= formatDate(datetime, format) %}
Where the first string is the date attribute and the second value is how you would like the date to be converted and displayed.
If a date pattern is invalid the date will fallback to ISO standard format.
You can use Java date formatting functions as summarized in Oracle documentation
Example
The following operation will return the date in the following format: MM/DD/YY.
{%= formatDate(profile.timeSeriesEvents._mobile.hotelBookingDetails.bookingDate, "MM/dd/YY") %}
The formatDate
function is used to format a date time value into its corresponding language sensitive representation, i.e in a desired locale. The format should be a valid Java DateTimeFormat pattern.
Syntax
{%= formatDate(datetime, format, locale) %}
Where the first string is the date attribute, second value is how you would like the date to be converted and displayed and the third value represents the locale in string format.
If a date pattern is invalid the date will fallback to ISO standard format.
You can use Java date formatting functions as summarized in Oracle documentation.
You can use formatting and valid locales as summarized in Oracle documentation and Supported locales.
Example
The following operation will return the date in the following format: MM/DD/YY and locale FRANCE.
{%= formatDate(profile.timeSeriesEvents._mobile.hotelBookingDetails.bookingDate, "MM/DD/YY", "fr_FR") %}
The getCurrentZonedDateTime
function returns the current date and time with time zone information.
Syntax
{%= getCurrentZonedDateTime() %}
{%= getCurrentZonedDateTime() %}
2024-12-06T17:22:02.281067+05:30[Asia/Kolkata]
The diffInHours
function returns the difference between two dates in terms of hours.
Syntax
{%= diffInHours(endDate, startDate) %}
{%= diffInHours(stringToDate("2024-11-01T17:19:51Z"), stringToDate("2024-11-01T07:19:51Z"))%}
10
The diffInMinutes
function is used to return the difference between two dates in terms of minutes.
Syntax
{%= diffInMinutes(endDate, startDate) %}
{%= diffInMinutes(stringToDate("2024-11-01T17:19:51Z"), stringToDate("2024-11-01T16:19:51Z"))%}
60
The diffInMonths
function returns the difference between two dates in terms of months.
Syntax
{%= diffInMonths(endDate, startDate) %}
{%=diffInMonths(stringToDate("2024-11-01T17:19:51Z"), stringToDate("2024-08-01T17:19:51Z"))%}
3
The setDays
function is used to set the day of the month for the given date-time.
Syntax
{%= setDays(datetime, day) %}
The setHours
function is used to set the hour of the date-time.
Syntax
{%= setHours(datetime, hour) %}
The ToDateTime
function converts string to date. It returns the epoch date as output for invalid input.
Syntax
{%= toDateTime(string, string) %}
{%=toDateTime("2024-11-01T17:19:51Z")%}
2024-11-01T17:19:51Z
The toUTC
function is used to convert a datetime to UTC.
Syntax
{%= toUTC(datetime) %}
The truncateToStartOfDay
function is used to modify a given date-time by setting it to the start of the day with the time set to 00:00.
Syntax
{%= truncateToStartOfDay(date) %}
{%= truncateToStartOfDay(stringToDate("2024-11-01T17:19:51Z")) %}
2024-11-01T00:00Z
The truncateToStartOfQuarter
function is used to truncate a date-time to the first day of its quarter (e.g., Jan 1, Apr 1, Jul 1, Oct 1) at 00:00.
Syntax
{%= truncateToStartOfQuarter(dateTime) %}
{%=truncateToStartOfQuarter(stringToDate("2024-11-01T17:19:51Z"))%}
2024-10-01T00:00Z
The truncateToStartOfWeek
function modifies a given date-time by setting it to the start of the week(Monday at 00:00).
Syntax
{%= truncateToStartOfWeek(dateTime) %}
truncateToStartOfWeek(stringToDate("2024-11-19T17:19:51Z"))%} // tuesday
2024-11-18T00:00Z // monday
The truncateToStartOfYear
function is used to modify a given date-time by truncating it to the first day of the year (January 1st) at 00:00.
Syntax
{%= truncateToStartOfYear(dateTime) %}
{%=truncateToStartOfYear(stringToDate("2024-11-01T17:19:51Z"))%}
2024-01-01T00:00Z
The weekOfYear
function is used to retrieve the week of the year.
Syntax
{%= weekOfYear(datetime) %}
The diffInYears
function is used to return the difference between two dates in terms of years.
Syntax
{%= diffInYears(endDate, startDate) %}: int
{%=diffInYears(stringToDate("2024-11-01T17:19:51Z"), stringToDate("2019-10-01T17:19:51Z"))%}
5