Articles on: Expression language

Date functions

Date

Format date value. NB! You need to use the Date formatter.
{% date({dateString}, {timezone}, {addDays}, {outputFormat}, {inputFormat}) %}

Examples of the function "Date":
Display current time
{% date('now') %}

Specify timezone
{% date({dateValue}, 'UTC') %}

Specify output format
{% date({dateValue}, 'UTC', 0, 'd/m/Y') %}

Specify output and input format
{% date({dateValue}, 'UTC', 0, 'd/m/Y', 'm/d/Y') %}



Datetime

Format datetime value. NB! You need to use the Date formatter.
{% datetime({datetimeString}, {timezone}, {addDays}, {outputFormat}, {inputFormat}) %}

Examples of the function "Datetime":
Display current time
{% datetime('now') %}

Specify timezone
{% datetime({dateValue}, 'UTC') %}

Specify output format
{% datetime({dateValue}, 'UTC', 0, 'd/m/Y H:i:s') %}

Specify output and input format
{% datetime({dateValue}, 'UTC', 0, 'd/m/Y H:i:', 'm/d/Y H:i:') %}


When using the T separator in a date format you need to escape it like this
Y-m-d\THH:mm:ss



Date difference

The date_diff function calculates a difference between two dates. You can also specify the {inputFormat} to hint date format. If date strings use known format then it is handled automatically..
{% date_diff({datetimeString}, {datetimeString}, {inputFormat}) %}


You can use date('now') function as the date value to find difference between today and another date.
{% date_diff(date('now'), '2021-09-15', 'Y-m-d') %}

The {inputFormat} parameter in the date_diff function is by default 'Y-m-d H:i:s'

Updated on: 18/12/2022

Was this article helpful?

Share your feedback

Cancel

Thank you!