Query by Date

Exact Date - this queries for all the articles with the release-date field (Date) equal to January 22, 2017. Note that this only works for the Date Field, not the Time Stamp field.

Copy
      api.query(
    Prismic.Predicates.at('my.article.release-date', new Date('2017-01-22'))
).then(function(content) {
    // content is the response object, content.results holds the documents
});
    
Copy
      $content = $api->query(
    Predicates::at('my.article.release-date', '2017-01-22')
);
// $content contains the response object, $content->getResults() holds the documents
    
Copy
      date = Date.new(2017, 1, 22)
content = api.query(
    Prismic::Predicates.at("my.article.release-date", date.strftime())
)
# content is the response object, content.results holds the documents
    

Here is an example of a query for all documents of the type “blog-post” whose release-date is in the month of May in the year 2016. This might be useful for a blog archive.

Copy
      api.query([
    Prismic.Predicates.month('my.blog-post.release-date', 'May'),
    Prismic.Predicates.year('my.blog-post.release-date', 2016)
]).then(function(blogPosts) {
    // blogPosts is the response object, blogPosts.results holds the documents
});
    
Copy
      $blogPosts = $api->query(
    [ Predicates::month('my.blog-post.release-date', 'May'),
      Predicates::year('my.blog-post.release-date', 2016) ]
);
// $blogPosts is the response object, $blogPosts->getResults() holds the documents
    
Copy
      blog_posts = api.query([
    Prismic::Predicates.month("my.blog-post.release-date", "May"),
    Prismic::Predicates.year("my.blog-post.release-date", 2016)
])
# blog_posts is the response object, blog_posts.results holds the documents
    

You can also query document by their publications date

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
      api.query([
    Prismic.Predicates.at('document.type', 'blog-post'),
    Prismic.Predicates.month('document.first_publication_date', 'May'),
    Prismic.Predicates.year('document.first_publication_date', 2016)
]).then(function(blogPosts) {
    // blogPosts is the response object, blogPosts.results holds the documents
});
    
Copy
      $blogPosts = $api->query(
    [ Predicates::at('document.type', 'blog-post'),
      Predicates::month('document.first_publication_date', 'May'),
      Predicates::year('document.first_publication_date', 2016) ]
);
// $blogPosts contains the response object, $blogPosts->getResults() contains the documents
    
Copy
      blog_posts = api.query([
      Prismic::Predicates.at("document.type", "blog-post"),
      Prismic::Predicates.month("document.first_publication_date", "May"),
      Prismic::Predicates.year("document.first_publication_date", 2016)
])
# blog_posts is the response object, blog_posts.results holds the documents
    

There are many more Date & Time based Predicates available. To learn more about what is available and how to use them, check out the Date & Timestamp page.