Date Templating

The Date field allows content writers to add a date that represents a calendar day.

Default Format

Here’s an example of how to integrate a Date field into your template.

  • ejs
  • pug
  • pug (API v1)
Copy
<span class="date">
  <%= PrismicDOM.Date(document.data.postDate) %>
</span>
Copy
span.date !{ PrismicDOM.Date(document.data.postDate) }
Copy
span.date !{ document.getDate('post.date').toDateString() }

Custom Format

You can change the format dates are displayed by using DateTimeFormat and adjusting the parameters to your needs.

  • ejs
  • pug
  • pug (API v1)
Copy
<span class="date">
  <%= Intl.DateTimeFormat('en-US',{ year: 'numeric', month: 'short', day:'2-digit' }).format(PrismicDOM.Date(document.data.postDate)) %>
</span>
Copy
span.date
  = Intl.DateTimeFormat('en-US',{ year: 'numeric', month: 'short', day: '2-digit' }).format(PrismicDOM.Date(document.data.postDate))
Copy
span.date
  = Intl.DateTimeFormat('en-US',{ year: 'numeric', month: 'short', day: '2-digit' }).format(document.getDate('post.postDate'))