Templating the Date field
The Date field allows content writers to add a date that represents a calendar day.
This article assumes the following:
1. That you have saved the document object in a variable named document as shown in the Retrieve the document object page.
2. That you have included the prismic-dom library as a dependency in your project.
Access the default date string
Here is an example that shows how to access the Date field value as the default string. In this case the Date field has the API ID of event_date.
const dateString = document.event_date;
Convert the date to a DateTime object
Here's an example of how to convert the Date string to a DateTime object using the PrismicDOM.date() function. In this case, the Date field has the API ID of event_date.
const PrismicDOM = require('prismic-dom'); const dateObject = PrismicDOM.Date(document.event_date);