11tyThe possum is Eleventy’s mascot

Eleventy Documentation

This is an older version of Eleventy. Full release history. Go to the newest Eleventy docs. You could try /docs/dates/ although it may not exist.
Documentation Menu

Content Dates #

Setting a Content Date in Front Matter #

Add a date key to your front matter to override the default date (file creation) and customize how the file is sorted in a collection.

Syntax YAML Front Matter
---
date: 2016-01-01
---
Syntax YAML Front Matter
---
date: Last Modified
---

Valid date values:

If a date key is omitted from the file, the date is assumed to be:

  1. If the file name has a YYYY-MM-DD format (anywhere), this date is used.
  2. File creation date.
Trying to use date in your templates? The date value will likely not be of much use, since Eleventy performs no transformation on this front matter value. You probably want page.date instead. Check out the values available in the page variable.

Dates off by one day? #

This is a Common Pitfall.

You’re probably displaying UTC dates in a local time zone.

Many date formats in Eleventy (when set in your content‘s filename as YYYY-MM-DD-myfile.md or in your front matter as date: YYYY-MM-DD) assume midnight in UTC. When displaying your dates, make sure you’re using the UTC time and not your own local time zone, which may be the default.

Example #

---
date: 2018-01-01
---
{{ page.date }} will display a local time zone date.
Mon Jan 01 2018 00:00:00 GMT+0000 (Coordinated Universal Time)
{{ page.date.toString() }} will display a local time zone date.
Mon Jan 01 2018 00:00:00 GMT+0000 (Coordinated Universal Time)
{{ page.date.toUTCString() }} will display a UTC time zone date.
Mon, 01 Jan 2018 00:00:00 GMT

Collections out of order when you run Eleventy on your Server? #

This is a Common Pitfall.

Be careful relying on the default date associated with a piece of content. By default Eleventy uses file creation dates, which works fine if you run Eleventy locally but may reset in some conditions if you run Eleventy on a Continuous Integration server. Work around this by using explicit date assignments, either in your front matter or your content’s file name. Read more at Content Dates.