> For the complete documentation index, see [llms.txt](https://documentation.crossengage.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://documentation.crossengage.io/data-and-engagement-platform/messages/personalization/formatting-functions/date-formatting.md).

# 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:

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

{% hint style="info" %}
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.
{% endhint %}

<table data-header-hidden><thead><tr><th width="159.66666666666669">Property</th><th width="92">Type</th><th>Description</th></tr></thead><tbody><tr><td>Property</td><td>Type</td><td>Description</td></tr><tr><td><code>dateTrait</code></td><td>string</td><td><strong>Optional</strong>. The user attribute that is used for date formatting and calculations. If omitted, the value '<strong>now'</strong> is used, which takes the system time at the time of dispatch.<br>e.g user.[traits.birthday]</td></tr><tr><td><code>timePhrase</code></td><td>string</td><td><strong>Required</strong>. The operation that is executed on the <code>dateTrait</code>. If you want to use the dateTrait directly, simply set the timePhrase e.g. <code>+1 hour</code>, <code>+2 days</code>. This attribute is required even if you wish to display the current date: to do so, simply set the time phrase equal to <code>0</code> or <code>now</code>.</td></tr><tr><td>outputFormat</td><td>string</td><td><strong>Required</strong>. The format the function should output. All common date formats are supported e.g. <code>yyyy-MM-dd</code>, <code>dd/MM/yy</code>.</td></tr></tbody></table>

#### Displaying the date 10 days from a user's birthday

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

```jsx
{{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.

{% hint style="info" %}
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).&#x20;

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).
{% endhint %}

{% hint style="warning" %}
Please note that it lower-/uppercasing matters - `dd`is not the same as`DD,as`lower 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.
{% endhint %}

Some [examples](https://www.joda.org/joda-time/key_format.html) (for 2024-05-10 14:15:55.978):

| Symbol | Meaning                      | Example |
| ------ | ---------------------------- | ------- |
| 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     |


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://documentation.crossengage.io/data-and-engagement-platform/messages/personalization/formatting-functions/date-formatting.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
