Articles on: Expression language

Date functions

Date

Format date value.
{% 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\TH:i:s


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'

When configuring the outputFormat and inputFormat parameters of date/datetime/date_diff function, please refer to the table below for a clear explanation of the supported formats. This will ensure the Date component processes and displays dates as intended.

FormatDescriptionExample Output
Day
dThe day of the month (two digits, leading zeros)01 to 31
DA textual representation of a day (three letters)Mon through Sun
jThe day of the month without leading zeros1 to 31
lA full textual representation of the daySunday through Saturday
NISO-8601 numeric representation of the day (1 = Monday, 7 = Sunday)1 to 7
SEnglish ordinal suffix for the day of the month (2 characters: st, nd, rd, or th)1st, 2nd, 3rd
wNumeric representation of the day (0 = Sunday, 6 = Saturday)0 to 6
zThe day of the year0 through 365
Week
WISO-8601 week number of year (weeks starting on Monday)01 to 53
Month
FA full textual representation of a monthJanuary through December
mNumeric representation of a month (two digits, leading zeros)01 to 12
MA short textual representation of a month (three letters)Jan through Dec
nNumeric representation of a month (without leading zeros)1 to 12
tThe number of days in the given month28 to 31
Year
LWhether it's a leap year (1 if it is a leap year, 0 otherwise)0 or 1
oISO-8601 year number2023
YA full numeric representation of a year (four digits)2023
yA two-digit representation of a year23
Time
aLowercase am or pmam, pm
AUppercase AM or PMAM, PM
BSwatch Internet time000 to 999
g12-hour format of an hour (no leading zeros)1 to 12
G24-hour format of an hour (no leading zeros)0 to 23
h12-hour format of an hour (two digits, leading zeros)01 to 12
H24-hour format of an hour (two digits, leading zeros)00 to 23
iMinutes with leading zeros00 to 59
sSeconds, with leading zeros00 to 59
uMicroseconds654321
Timezone
eTimezone identifierUTC, GMT, Europe/Paris
IWhether the date is in Daylight Savings Time (1 if DST, 0 otherwise)0 or 1
ODifference to Greenwich time (GMT) in hours+0200
PDifference to Greenwich time (GMT) with colon between hours and minutes+02:00
TTimezone abbreviationEST, MDT
ZTimezone offset in seconds (west of UTC is negative, east of UTC is positive)-43200 to 50400
Full Date/Time
cISO-8601 date2023-01-14T23:59:59+00:00
rRFC 2822 formatted dateSat, 14 Jan 2023 23:59:59 +0000
USeconds since the Unix Epoch (January 1 1970 00:00:00 GMT)1673740799




Date component
Is it possible to conditionally change the component style or hide the component?
How to add page numbers?

Updated on: 21/01/2025

Was this article helpful?

Share your feedback

Cancel

Thank you!