Skip to content

40%off everything for Black Friday, with code . Until Dec 1.

Bright Themes

How the date helper works in Ghost

The {{date}} helper formats dates in a Ghost theme, from "Apr 7, 2024" to "2 days ago": its options, format tokens and examples to copy.

Norbert3 min read

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:

Handlebars
{{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).
  • locale and timezone: 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:

Handlebars
{{#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:

Handlebars
Updated {{date updated_at format="MMM D, YYYY"}}

Time ago:

Handlebars
{{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:

Handlebars
{{date published_at format="LL" locale="fr" timezone="Europe/Paris"}}
{{!-- Outputs: 7 avril 2024 --}}

The year in the footer:

Handlebars
<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/2024
  • LL: April 7, 2024
  • ll: 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:

FormatExample
YYYY-MM-DD2024-04-07
MM/DD/YYYY04/07/2024
DD/MM/YYYY07/04/2024
MMM D, YYYYApr 7, 2024
MMMM D, YYYYApril 7, 2024
MMMM Do, YYYYApril 7th, 2024
ddd, MMM D, YYYYSun, Apr 7, 2024
dddd, MMMM D, YYYYSunday, April 7, 2024
YYYY-MM-DD HH:mm:ss2024-04-07 12:30:45
h:mm A12:30 PM
HH:mm12:30
MMM YYYYApr 2024
YYYY2024

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 datetime attribute: always YYYY-MM-DD, so browsers and search engines read it.
  • Archive pages: MMMM YYYY to 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.

Related posts

More on helpers

Get the Bright Themes newsletter

New tutorials and explainers, what changed in Ghost, and our theme releases. No spam, unsubscribe anytime.

Get the Bright Themes newsletter

New tutorials and explainers, what changed in Ghost, and our theme releases. No spam, unsubscribe anytime.