On this page
The {{date}} helper (opens in a new tab) prints a date in the format you choose. Themes use it for the publish date of a post, the “updated” date, dates on archive pages and the year in the footer. It formats dates with Moment.js (opens in a new tab), so it takes Moment’s format tokens.
How it works
Pass it a date and a format:
{{date published_at format="MMM D, YYYY"}}
{{!-- Outputs: Apr 7, 2024 --}}The options:
format: how to write the date, with the tokens below. Without it, Ghost uses Moment’s short localized format,ll(“Apr 7, 2024” in English).localeandtimezone: replace your site’s defaults for this date. The defaults are your publication language and timezone, both set in Settings › General settings; the language is also what theme translations follow.timeago: prints the time since the date, such as “2 days ago”, instead of the date.
Without a date, the helper uses the post’s published_at when there is one (inside a post), and otherwise today’s date.
Examples
A post date, with a machine-readable datetime:
{{#post}}
<time datetime="{{date format="YYYY-MM-DD"}}">{{date format="D MMMM YYYY"}}</time>
{{/post}}
{{!-- Outputs: <time datetime="2024-04-07">7 April 2024</time> --}}The last update:
Updated {{date updated_at format="MMM D, YYYY"}}Time ago:
{{date published_at timeago="true"}}
{{!-- Outputs: 2 days ago --}}Note
On a site behind a cache, as on Ghost(Pro), “time ago” is counted from when the page was cached, not from when the visitor opens it. For exact dates, use a format.
Another language and timezone:
{{date published_at format="LL" locale="fr" timezone="Europe/Paris"}}
{{!-- Outputs: 7 avril 2024 --}}The year in the footer:
<p>© {{date format="YYYY"}} {{@site.title}}</p>Outside a post there is no published_at, so this prints the current year.
Format tokens
Moment replaces each token with part of the date. Combine them with any spaces, commas or other characters.
Year
YYYY: four-digit year (2024)YY: two-digit year (24)
Month
M: month number (1 to 12)MM: two-digit month (01 to 12)MMM: short month name (Jan, Feb)MMMM: full month name (January, February)
Day
D: day of the month (1 to 31)DD: two-digit day of the month (01 to 31)Do: day with an ordinal (1st, 2nd, 3rd)ddd: short day name (Mon, Tue)dddd: full day name (Monday, Tuesday)
Hours, minutes and seconds
HH: two-digit hour, 24-hour clock (00 to 23)hh: two-digit hour, 12-hour clock (01 to 12)h: hour, 12-hour clock (1 to 12)mm: two-digit minute (00 to 59)ss: two-digit second (00 to 59)A/a: AM or PM / am or pm
Localized formats
These follow the date format of the locale, so they suit multilingual sites:
L: 04/07/2024LL: April 7, 2024ll: Apr 7, 2024 (the default)LLL: April 7, 2024 12:30 PM
The full list is in the Moment.js format docs (opens in a new tab).
Common formats
Examples for Sunday, April 7, 2024, at 12:30:45 in the afternoon:
| Format | Example |
|---|---|
YYYY-MM-DD | 2024-04-07 |
MM/DD/YYYY | 04/07/2024 |
DD/MM/YYYY | 07/04/2024 |
MMM D, YYYY | Apr 7, 2024 |
MMMM D, YYYY | April 7, 2024 |
MMMM Do, YYYY | April 7th, 2024 |
ddd, MMM D, YYYY | Sun, Apr 7, 2024 |
dddd, MMMM D, YYYY | Sunday, April 7, 2024 |
YYYY-MM-DD HH:mm:ss | 2024-04-07 12:30:45 |
h:mm A | 12:30 PM |
HH:mm | 12:30 |
MMM YYYY | Apr 2024 |
YYYY | 2024 |
When to use which
- Post cards and post pages: a short, readable format such as
MMM D, YYYY, or the default, often next to the reading time. - Multilingual sites: the localized formats (
ll,LL), which follow each language’s order and month names. - The
datetimeattribute: alwaysYYYY-MM-DD, so browsers and search engines read it. - Archive pages:
MMMM YYYYto group posts by month; see how to create a post archive page. - News and fast-moving sites:
timeago, if your pages aren’t cached for long.