Date Filters
Filters for formatting and manipulating date and time values.
Formatting
| Filter | Arguments | Description |
|---|---|---|
date | format, timezone | Format date |
date_i18n | format | Format with WordPress localization |
time_ago | to_date | Human-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
| Filter | Arguments | Description |
|---|---|---|
date_modify | modifier | Modify 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
| Code | Description | Example |
|---|---|---|
Y | 4-digit year | 2024 |
y | 2-digit year | 24 |
m | Month (01-12) | 01 |
n | Month (1-12) | 1 |
F | Full month name | January |
M | Short month name | Jan |
d | Day (01-31) | 15 |
j | Day (1-31) | 15 |
D | Short weekday | Mon |
l | Full weekday | Monday |
Time
| Code | Description | Example |
|---|---|---|
H | Hour 24h (00-23) | 14 |
G | Hour 24h (0-23) | 14 |
h | Hour 12h (01-12) | 02 |
g | Hour 12h (1-12) | 2 |
i | Minutes (00-59) | 30 |
s | Seconds (00-59) | 45 |
A | AM/PM | PM |
a | am/pm | pm |
Other
| Code | Description | Example |
|---|---|---|
U | Unix timestamp | 1705330245 |
c | ISO 8601 | 2024-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') }}