Date Formatting

The computeDate function can be used to calculate a date, or to change the displayed format of the date. The syntax of this function is:

{{computeDate '{
    "dateTrait": [User attribute], 
    "timePhrase": [Time phrase], 
    "outputFormat": [Output format]
    }'
}}

While the computeDate function can alter how dates are displayed, the format in which dates are sent to CrossEngage must remain the same: ISO8601 format in UTC (Coordinated Universal Time). This can be written as yyyy-MM-dd.

Property

Type

Description

dateTrait

string

Optional. The user attribute that is used for date formatting and calculations. If omitted, the value 'now' is used, which takes the system time at the time of dispatch. e.g user.[traits.birthday]

timePhrase

string

Required. The operation that is executed on the dateTrait. If you want to use the dateTrait directly, simply set the timePhrase e.g. +1 hour, +2 days. This attribute is required even if you wish to display the current date: to do so, simply set the time phrase equal to 0 or now.

outputFormat

string

Required. The format the function should output. All common date formats are supported e.g. yyyy-MM-dd, dd/MM/yy.

Displaying the date 10 days from a user's birthday

For this example, we output the date 10 days from the User's birthday.

{{computeDate '{
    "dateTrait": "user.[traits.birthday]",
    "timePhrase": "+ 10 days", 
    "outputFormat": "yyyy-MM-dd"
    }'
}}

For example, if the User has his next birthday on 2022-01-01, it would compute the date 2022-01-11.

Depending on how many characters are used, the dateformat is either single- or double digits, e.g. "yyyy-MM-dd" will result in a date with leading zeros for month and date (2022-01-11), "y-M-d" without leading zeros (2022-1-11).

The year is also a special case were "y", "yyy" and "yyyy" all output the full year (2022), wheras "yy" will output only the year of the century (22).

Please note that it lower-/uppercasing matters - ddis not the same asDD,aslower cased "dd" is the day of the month, whereas "DD" is the day of they year, e.g. the 1st of February is the 32nd day of the year.

Some examples (for 2024-05-10 14:15:55.978):

SymbolMeaningExample

Y/y

year of era/year

2024

w

week of year

19

E

day of week (text)

Fri

e

day of week (num)

5

d

day of month

10

M

month of year

5

m

minute of hour

15

a

halfday of day (AM/PM)

PM

K

hour of halfday (12h format)

2

H

hour of day (24h format)

14

s

second of minute

55

S

fraction of second

978

Last updated