Date & Timestamp

A Date represents a calendar day, Timestamp also includes a time.

The following defines a date:

Copy
      "birthdate" : {
  "type" : "Date",
  "fieldset" : "date",
  "config" : {
    "label" : "Birthdate"
  }
}
    

The following defines a date with a timestamp:

Copy
      "birthdate" : {
  "type" : "Timestamp",
  "fieldset" : "timestamp",
  "config" : {
    "label" : "Birthdate & Time"
  }
}
    

type

string

Timestamp, Date

fieldset

string

a user-friendly field label

config

object

objects listed below

config

label

string

user-friendly label before the field

default

string

now

Query documents for a date equals to a specific day:

Copy
      api.query([
  prismic.Predicates.at("document.type", "blog-post"),
  prismic.Predicates.at("my.blog-post.date", new Date("2013-08-17"))
], { pageSize : 10 }).then(function(response) {
  // response.results holds the blog posts from the requested date
});
    
Copy
      $response = $api->query(array(
    Predicates::at("document.type", "blog-post"),
    Predicates::at("my.blog-post.date", new DateTime('2013-08-17'))
));
    
Copy
      Response response = api.query(
    Predicates.at("document.type", "blog-post"),
    Predicates.at("my.blog-post.date",  new DateTime(2013, 8, 17, 0, 0))
).submit();
    
Copy
      var response = await api.query(
    Predicates.at("document.type", "blog-post"),
    Predicates.at("my.blog-post.date",  new DateTime(2013, 8, 17, 0, 0))
).Submit();
    
Copy
      response = api.query([
    Predicates.at("document.type", "blog-post"),
    Predicates.at("my.blog-post.date",  Date.new(2013, 8, 7))
]);
    

Other time-based predicates:

Copy
      prismic.Predicates.dateAfter("my.blog-post.date", new Date("2013-08-17"))
prismic.Predicates.dateBefore("my.blog-post.date", new Date("2013-08-17"))
prismic.Predicates.dateBetween("my.blog-post.date", new Date("2013-08-17"), new Date())
prismic.Predicates.dayOfMonth("my.blog-post.date", 25)
prismic.Predicates.dayOfMonthAfter("my.blog-post.date", 24)
prismic.Predicates.dayOfMonthBefore("my.blog-post.date", 26)
prismic.Predicates.dayOfWeek("my.blog-post.date", "Tuesday")
prismic.Predicates.dayOfWeekAfter("my.blog-post.date", "Tuesday")
prismic.Predicates.dayOfWeekBefore("my.blog-post.date", "Wednesday")
prismic.Predicates.month("my.blog-post.date", "September")
prismic.Predicates.monthAfter("my.blog-post.date", "August")
prismic.Predicates.monthBefore("my.blog-post.date", "November")
prismic.Predicates.year("my.blog-post.date", 2013)
prismic.Predicates.hour("my.blog-post.date", 12)
prismic.Predicates.hourAfter("my.blog-post.date", 12)
prismic.Predicates.hourBefore("my.blog-post.date", 12)
    
Copy
      Predicates::dateAfter("my.blog-post.date", new DateTime('2013-08-17'))
Predicates::dateBefore("my.blog-post.date", new DateTime('2013-08-17'))
Predicates::dateBetween("my.blog-post.date", new DateTime('2013-08-17'), new DateTime('NOW'))
Predicates::dayOfMonth("my.blog-post.date", 25)
Predicates::dayOfMonthAfter("my.blog-post.date", 24)
Predicates::dayOfMonthBefore("my.blog-post.date", 26)
Predicates::dayOfWeek("my.blog-post.date", "Tuesday")
Predicates::dayOfWeekAfter("my.blog-post.date", "Tuesday")
Predicates::dayOfWeekBefore("my.blog-post.date", "Wednesday")
Predicates::month("my.blog-post.date", "September")
Predicates::monthAfter("my.blog-post.date", "August")
Predicates::monthBefore("my.blog-post.date", "November")
Predicates::year("my.blog-post.date", 2013)
Predicates::hour("my.blog-post.date", 12)
Predicates::hourAfter("my.blog-post.date", 12)
Predicates::hourBefore("my.blog-post.date", 12)
    
Copy
      Predicate dateBefore = Predicates.dateBefore("my.product.releaseDate", new DateTime(2014, 6, 1, 0, 0));
Predicate dateAfter = Predicates.dateAfter("my.product.releaseDate", new DateTime(2014, 1, 1, 0, 0));
Predicate dateBetween = Predicates.dateBetween("my.product.releaseDate", new DateTime(2014, 1, 1, 0, 0), new DateTime(2014, 6, 1, 0, 0));
Predicate dayOfMonth = Predicates.dayOfMonth("my.product.releaseDate", 14);
Predicate dayOfMonthAfter = Predicates.dayOfMonthAfter("my.product.releaseDate", 14);
Predicate dayOfMonthBefore = Predicates.dayOfMonthBefore("my.product.releaseDate", 14);
Predicate dayOfWeek = Predicates.dayOfWeek("my.product.releaseDate", Predicates.DayOfWeek.TUESDAY);
Predicate dayOfWeekAfter = Predicates.dayOfWeekAfter("my.product.releaseDate", Predicates.DayOfWeek.WEDNESDAY);
Predicate dayOfWeekBefore = Predicates.dayOfWeekBefore("my.product.releaseDate", Predicates.DayOfWeek.WEDNESDAY);
Predicate month = Predicates.month("my.product.releaseDate", Predicates.Month.JUNE);
Predicate monthBefore = Predicates.monthBefore("my.product.releaseDate", Predicates.Month.JUNE);
Predicate monthAfter = Predicates.monthAfter("my.product.releaseDate", Predicates.Month.JUNE);
Predicate year = Predicates.year("my.product.releaseDate", 2014);
Predicate hour = Predicates.hour("my.product.releaseDate", 12);
Predicate hourBefore = Predicates.hourBefore("my.product.releaseDate", 12);
Predicate hourAfter = Predicates.hourAfter("my.product.releaseDate", 12);

    
Copy
      Predicate dateBefore = Predicates.dateBefore("my.product.releaseDate", new DateTime(2014, 6, 1, 0, 0));
Predicate dateAfter = Predicates.dateAfter("my.product.releaseDate", new DateTime(2014, 1, 1, 0, 0));
Predicate dateBetween = Predicates.dateBetween("my.product.releaseDate", new DateTime(2014, 1, 1, 0, 0), new DateTime(2014, 6, 1, 0, 0));
Predicate dayOfMonth = Predicates.dayOfMonth("my.product.releaseDate", 14);
Predicate dayOfMonthAfter = Predicates.dayOfMonthAfter("my.product.releaseDate", 14);
Predicate dayOfMonthBefore = Predicates.dayOfMonthBefore("my.product.releaseDate", 14);
Predicate dayOfWeek = Predicates.dayOfWeek("my.product.releaseDate", Predicates.DayOfWeek.TUESDAY);
Predicate dayOfWeekAfter = Predicates.dayOfWeekAfter("my.product.releaseDate", Predicates.DayOfWeek.WEDNESDAY);
Predicate dayOfWeekBefore = Predicates.dayOfWeekBefore("my.product.releaseDate", Predicates.DayOfWeek.WEDNESDAY);
Predicate month = Predicates.month("my.product.releaseDate", Predicates.Month.JUNE);
Predicate monthBefore = Predicates.monthBefore("my.product.releaseDate", Predicates.Month.JUNE);
Predicate monthAfter = Predicates.monthAfter("my.product.releaseDate", Predicates.Month.JUNE);
Predicate year = Predicates.year("my.product.releaseDate", 2014);
Predicate hour = Predicates.hour("my.product.releaseDate", 12);
Predicate hourBefore = Predicates.hourBefore("my.product.releaseDate", 12);
Predicate hourAfter = Predicates.hourAfter("my.product.releaseDate", 12);

    
Copy
      Predicates.date_after("my.blog-post.date", new DateTime('2013-08-17'))
Predicates.date_before("my.blog-post.date", new DateTime('2013-08-17'))
Predicates.date_between("my.blog-post.date", new DateTime('2013-08-17'), new DateTime('NOW'))
Predicates.day_of_month("my.blog-post.date", 25)
Predicates.day_of_month_after("my.blog-post.date", 24)
Predicates.day_of_month_before("my.blog-post.date", 26)
Predicates.day_of_week("my.blog-post.date", "Tuesday")
Predicates.day_of_week_after("my.blog-post.date", "Tuesday")
Predicates.day_of_week_before("my.blog-post.date", "Wednesday")
Predicates.month("my.blog-post.date", "September")
Predicates.month_after("my.blog-post.date", "August")
Predicates.month_before("my.blog-post.date", "November")
Predicates.year("my.blog-post.date", 2013)
Predicates.hour("my.blog-post.date", 12)
Predicates.hour_after("my.blog-post.date", 12)
Predicates.hour_before("my.blog-post.date", 12)
    

Time-related predicates are strict inequalities, in other words the date (or time) corresponding to the bounds is not returned in the results. If you need an inclusive query, you should offset the bound by one day (or second).

Orderings

Date and timestamp fields can be used to order results.

Copy
      /*
Acending: '[my.blog-post.date]'
Descending: '[my.blog-post.date desc]'
*/
api.query([
  prismic.Predicates.at("document.type", "blog-post"),
  prismic.Predicates.at("my.blog-post.date", new Date("2013-08-17"))
], { pageSize : 10, orderings: '[my.blog-post.date desc]' }
).then(function(response) {
  // response.results holds the blog posts on requested date in descending order
});
    
Copy
      $response = $api
    ->query(Predicates::at("document.type", "blog-post"))
    ->orderings('[my.blog-post.date desc]')
    ->submit();
    
Copy
      Response response = api
    .query(Predicates.at("document.type", "blog-post"))
    .orderings("my.blog-post.date")
    .submit();
    
Copy
      var response = await api
    .query(Predicates.at("document.type", "blog-post"))
    .orderings("my.blog-post.date")
    .Submit();
    
Copy
      response = api
    .query(Predicates.at("document.type", "blog-post"))
    .orderings("my.blog-post.date")
    .submit
    
Copy
      input(type='text', value=prismicdoc.getDate('blog-post.date').toISOString())
    
Copy
      <input type="text" value="<?= $prismicdoc->getDate('blog-post.date')->asText() ?>"/>
    
Copy
      <input type="text" value="${prismicdoc.getDate("blog-post.date").asText()}"/>
    
Copy
      <input type="text" value="@Model.prismicdoc.GetDate("blog-post.date").AsText()}"/>
    
Copy
      <input type="text" value="<%= @document.get_date("blog-post.date").as_text %>"/>