Skip to main content

Date Filters

Filters for formatting and manipulating date and time values.

Formatting

FilterArgumentsDescription
dateformat, timezoneFormat date
date_i18nformatFormat with WordPress localization
time_agoto_dateHuman-readable time difference

date

Arguments:

  • format — PHP date format (default: WordPress date format setting)
  • timezone — Timezone string (optional)
{{ post.date|date }}                           <!-- Uses WP setting -->
{{ post.date|date('F j, Y') }} <!-- January 15, 2024 -->
{{ post.date|date('Y-m-d') }} <!-- 2024-01-15 -->
{{ post.date|date('m/d/Y') }} <!-- 01/15/2024 -->
{{ post.date|date('H:i') }} <!-- 14:30 -->
{{ post.date|date('g:i A') }} <!-- 2:30 PM -->
{{ post.date|date('c') }} <!-- ISO 8601 -->
{{ post.date|date('F j, Y', 'America/New_York') }}

date_i18n

Uses WordPress date_i18n() for translated date names.

{{ post.timestamp|date_i18n('F j, Y') }}

time_ago

Returns human-readable time difference ("3 days ago", "2 hours from now").

Arguments:

  • to_date — Compare to this date (default: current time)
{{ post.date|time_ago }}                       <!-- 2 days ago -->
{{ post.date|time_ago }} <!-- 3 hours ago -->
{{ event.date|time_ago }} <!-- 5 days from now -->

Date Modification

FilterArgumentsDescription
date_modifymodifierModify date

Modifier examples:

  • '+1 day', '-1 week', '+1 month', '+1 year'
  • 'next monday', 'last friday'
  • 'first day of this month', 'last day of this month'
{{ post.date|date_modify('+1 day')|date('F j, Y') }}
{{ post.date|date_modify('+1 week')|date('F j, Y') }}
{{ post.date|date_modify('-2 weeks')|date('F j, Y') }}
{{ post.date|date_modify('next monday')|date('F j, Y') }}
{{ post.date|date_modify('first day of this month')|date('F j, Y') }}

Format Codes

Date

CodeDescriptionExample
Y4-digit year2024
y2-digit year24
mMonth (01-12)01
nMonth (1-12)1
FFull month nameJanuary
MShort month nameJan
dDay (01-31)15
jDay (1-31)15
DShort weekdayMon
lFull weekdayMonday

Time

CodeDescriptionExample
HHour 24h (00-23)14
GHour 24h (0-23)14
hHour 12h (01-12)02
gHour 12h (1-12)2
iMinutes (00-59)30
sSeconds (00-59)45
AAM/PMPM
aam/pmpm

Other

CodeDescriptionExample
UUnix timestamp1705330245
cISO 86012024-01-15T14:30:45+00:00

Common Patterns

Publication date

{{ post.date|date('F j, Y') }}

Relative time

{{ post.date|time_ago }}

Datetime attribute

<time datetime="{{ post.date|date('c') }}">
{{ post.date|date('F j, Y') }}
</time>

Expiry calculation

{{ event.date|date_modify('+30 days')|date('F j, Y') }}