Query by Date

This page shows multiple ways to query documents based on a date field.

Before reading

This page assumes that you're using the Vue.js starter project or that you have setup your project as explained on the Integrating with existing project page.

Here we use a few predicates that can query based on Date or Timestamp fields. Feel free to explore the Date & Time based Predicate Reference page to learn more about this.

Query a Date Field by an exact date

Here is an example of how to query for all the articles with the release_date field (Date Field) equal to January 22, 2017. Note that this only works for the Date Field, not the Time Stamp field.

Copy
this.$prismic.client.query(
  this.$prismic.Predicates.at('my.article.release_date', '2018-06-20')
).then((response) => {
  // response is the response object, response.results holds the documents
});

Query a Date Field that falls in a certain month & year

Here is an example of a query for all documents of the type "blog_post" whose release_date field (Date field) is in the month of May in the year 2016. This might be useful for a blog archive.

Copy
this.$prismic.client.query([
  this.$prismic.Predicates.month('my.blog_post.release_date', 'May'),
  this.$prismic.Predicates.year('my.blog_post.release_date', 2016)
]).then((response) => {
  // response is the response object, response.results holds the documents
});

Query by Publication Dates

You can also query document by their publications dates.

Here is an example of a query for all documents of the type "blog_post" whose original publication date is in the month of May in the year 2016.

Copy
this.$prismic.client.query([
  this.$prismic.Predicates.at('document.type', 'blog_post'),
  this.$prismic.Predicates.month('document.first_publication_date', 'May'),
  this.$prismic.Predicates.year('document.first_publication_date', 2016)
]).then((response) => {
  // response is the response object, response.results holds the documents
});