Date & Time based Predicate Reference
This page describes and gives examples for all the date and time based predicates you can use when creating queries with the prismic.io Ruby development kit.
All of these predicates will work when used with either the Date or Timestamp fields, as well as the first and last publication dates.
Note that when using any of these predicates with either a Date or Timestamp field, you will limit the results of the query to the specified custom type.
The date_after predicate checks that the value in the path is after the date value passed into the predicate.
This will not include anything with a date equal to the input value.
Prismic::Predicates.date_after( path, date )
path
accepted paths
document.first_publication_date
document.last_publication_date
my.{custom-type}.{field}
date
accepted date values
Date object: Date.new(YYYY, MM, DD)
String in the following format: "YYYY-MM-DD"
Examples:
Prismic::Predicates.date_after("document.first_publication_date", Date.new(2017, 5, 18))
Prismic::Predicates.date_after("document.last_publication_date", "2016-07-22")
Prismic::Predicates.date_after("my.article.release-date", "2017-01-23")
The date_before predicate checks that the value in the path is before the date value passed into the predicate.
This will not include anything with a date equal to the input value.
Prismic::Predicates.date_before( path, date )
path
accepted paths
document.first_publication_date
document.last_publication_date
my.{custom-type}.{field}
date
accepted date values
Date object: Date.new(YYYY, MM, DD)
String in the following format: "YYYY-MM-DD"
Examples:
Prismic::Predicates.date_before("document.first_publication_date", "2016-09-19")
Prismic::Predicates.date_before("document.last_publication_date", Date.new(2016, 10, 15))
Prismic::Predicates.date_before("my.post.date", Date.new(2016, 08, 24))
The date_between predicate checks that the value in the path is within the date values passed into the predicate.
Prismic::Predicates.date_between( path, start_date, end_date )
path
accepted paths
document.first_publication_date
document.last_publication_date
my.{custom-type}.{field}
start_date
accepted date values
Date object: Date.new(YYYY, MM, DD)
String in the following format: "YYYY-MM-DD"
end_date
accepted date values
Date object: Date.new(YYYY, MM, DD)
String in the following format: "YYYY-MM-DD"
Examples:
Prismic::Predicates.date_between("document.first_publication_date", "2017-01-16", "2017-02-16")
Prismic::Predicates.date_between("document.last_publication_date", Date.new(2017, 01, 16), Date.new(2017, 02, 16))
Prismic::Predicates.date_between("my.blog-post.post-date", "2016-06-01", "2016-06-30")
The day_of_month predicate checks that the value in the path is equal to the day of the month passed into the predicate.
Prismic::Predicates.day_of_month( path, day )
path
accepted paths
document.first_publication_date
document.last_publication_date
my.{custom-type}.{field}
day
integer
Day of the month
Examples:
Prismic::Predicates.day_of_month("document.first_publication_date", 22)
Prismic::Predicates.day_of_month("document.last_publication_date", 30)
Prismic::Predicates.day_of_month("my.post.date", 14)
The day_of_month_after predicate checks that the value in the path is after the day of the month passed into the predicate.
Note that this will return only the days after the specified day of the month. It will not return any documents where the day is equal to the specified day.
Prismic::Predicates.day_of_month_after( path, day )
path
accepted paths
document.first_publication_date
document.last_publication_date
my.{custom-type}.{field}
day
integer
Day of the month
Examples:
Prismic::Predicates.day_of_month_after("document.first_publication_date", 10)
Prismic::Predicates.day_of_month_after("document.last_publication_date", 15)
Prismic::Predicates.day_of_month_after("my.event.date-and-time", 21)
The day_of_month_before predicate checks that the value in the path is before the day of the month passed into the predicate.
Note that this will return only the days before the specified day of the month. It will not return any documents where the date is equal to the specified day.
Prismic::Predicates.day_of_month_before( path, day )
path
accepted paths
document.first_publication_date
document.last_publication_date
my.{custom-type}.{field}
day
integer
Day of the month
Examples:
Prismic::Predicates.day_of_month_before("document.first_publication_date", 15)
Prismic::Predicates.day_of_month_before("document.last_publication_date", 10)
Prismic::Predicates.day_of_month_before("my.blog-post.release-date", 23)
The day_of_week predicate checks that the value in the path is equal to the day of the week passed into the predicate.
Prismic::Predicates.day_of_week( path, week_day )
path
accepted paths
document.first_publication_date
document.last_publication_date
my.{custom-type}.{field}
week_day
string* or integer
"monday", "mon", or 1
"tuesday", "tue", or 2
"wednesday", "wed", or 3
"thursday", "thu", or 4
"friday", "fri", or 5
"saturday", "sat", or 6
"sunday", "sun", or 7
For any of the string input values you can use either first letter capitalized, all lowercase, or all uppercase. For example, "Monday", "monday", and "MONDAY" are all accepted values.
Examples:
Prismic::Predicates.day_of_week("document.first_publication_date", 1)
Prismic::Predicates.day_of_week("document.last_publication_date", "sunday")
Prismic::Predicates.day_of_week("my.concert.show-date", "Fri")
The day_of_week_after predicate checks that the value in the path is after the day of the week passed into the predicate.
This predicate uses Monday as the beginning of the week:
- Monday
- Tuesday
- Wednesday
- Thursday
- Friday
- Saturday
- Sunday
Note that this will return only the days after the specified day of the week. It will not return any documents where the day is equal to the specified day.
Prismic::Predicates.day_of_week_after( path, week_day )
path
accepted paths
document.first_publication_date
document.last_publication_date
my.{custom-type}.{field}
week_day
string* or integer
"monday", "mon", or 1
"tuesday", "tue", or 2
"wednesday", "wed", or 3
"thursday", "thu", or 4
"friday", "fri", or 5
"saturday", "sat", or 6
"sunday", "sun", or 7
For any of the string input values you can use either first letter capitalized, all lowercase, or all uppercase. For example, "Monday", "monday", and "MONDAY" are all accepted values.
Examples:
Prismic::Predicates.day_of_week_after("document.first_publication_date", "friday")
Prismic::Predicates.day_of_week_after("document.last_publication_date", "THU")
Prismic::Predicates.day_of_week_after("my.blog-post.date", 2)
The day_of_week_before predicate checks that the value in the path is before the day of the week passed into the predicate.
This predicate uses Monday as the beginning of the week:
- Monday
- Tuesday
- Wednesday
- Thursday
- Friday
- Saturday
- Sunday
Note that this will return only the days before the specified day of the week. It will not return any documents where the day is equal to the specified day.
Prismic::Predicates.day_of_week_before( path, week_day )
path
accepted paths
document.first_publication_date
document.last_publication_date
my.{custom-type}.{field}
week_day
string* or integer
"monday", "mon", or 1
"tuesday", "tue", or 2
"wednesday", "wed", or 3
"thursday", "thu", or 4
"friday", "fri", or 5
"saturday", "sat", or 6
"sunday", "sun", or 7
For any of the string input values you can use either first letter capitalized, all lowercase, or all uppercase. For example, "Monday", "monday", and "MONDAY" are all accepted values.
Examples:
Prismic::Predicates.day_of_week_before("document.first_publication_date", "Wed")
Prismic::Predicates.day_of_week_before("document.last_publication_date", 6)
Prismic::Predicates.day_of_week_before("my.page.release-date", "saturday")
The month predicate checks that the value in the path occurs in the month value passed into the predicate.
Prismic::Predicates.month( path, month )
path
accepted paths
document.first_publication_date
document.last_publication_date
my.{custom-type}.{field}
month
string* or integer
"january", "jan", or 1
"february", "feb", or 2
"march", "mar", or 3
"april", "apr", or 4
"may" or 5
"june", "jun", or 6
"july", "jul", or 7
"august", "aug", or 8
"september", "sep", or 9
"october", "oct", or 10
"november", "nov", or 11
"december", "dec", or 12
For any of the string input values you can use either first letter capitalized, all lowercase, or all uppercase. For example, "January", "january", and "JANUARY" are all accepted values.
Examples:
Prismic::Predicates.month("document.first_publication_date", "august")
Prismic::Predicates.month("document.last_publication_date", "Sep")
Prismic::Predicates.month("my.blog-post.date", 1)
The month_after predicate checks that the value in the path occurs in any month after the value passed into the predicate.
Note that this will only return documents where the date is after the specified month. It will not return any documents where the date is within the specified month.
Prismic::Predicates.month_after( path, month )
path
accepted paths
document.first_publication_date
document.last_publication_date
my.{custom-type}.{field}
month
string* or integer
"january", "jan", or 1
"february", "feb", or 2
"march", "mar", or 3
"april", "apr", or 4
"may" or 5
"june", "jun", or 6
"july", "jul", or 7
"august", "aug", or 8
"september", "sep", or 9
"october", "oct", or 10
"november", "nov", or 11
"december", "dec", or 12
For any of the string input values you can use either first letter capitalized, all lowercase, or all uppercase. For example, "January", "january", and "JANUARY" are all accepted values.
Examples:
Prismic::Predicates.month_after("document.first_publication_date", "February")
Prismic::Predicates.month_after("document.last_publication_date", 6)
Prismic::Predicates.month_after("my.article.date", "oct")
The month_before predicate checks that the value in the path occurs in any month before the value passed into the predicate.
Note that this will only return documents where the date is before the specified month. It will not return any documents where the date is within the specified month.
Prismic::Predicates.month_before( path, month )
path
accepted paths
document.first_publication_date
document.last_publication_date
my.{custom-type}.{field}
month
string* or integer
"january", "jan", or 1
"february", "feb", or 2
"march", "mar", or 3
"april", "apr", or 4
"may" or 5
"june", "jun", or 6
"july", "jul", or 7
"august", "aug", or 8
"september", "sep", or 9
"october", "oct", or 10
"november", "nov", or 11
"december", "dec", or 12
For any of the string input values you can use either first letter capitalized, all lowercase, or all uppercase. For example, "January", "january", and "JANUARY" are all accepted values.
Examples:
Prismic::Predicates.month_before("document.first_publication_date", 8)
Prismic::Predicates.month_before("document.last_publication_date", "june")
Prismic::Predicates.month_before("my.blog-post.release-date", "Sep")
The year predicate checks that the value in the path occurs in the year value passed into the predicate.
Prismic::Predicates.year( path, year )
path
accepted paths
document.first_publication_date
document.last_publication_date
my.{custom-type}.{field}
year
integer
Year
Examples:
Prismic::Predicates.year("document.first_publication_date", 2016)
Prismic::Predicates.year("document.last_publication_date", 2017)
Prismic::Predicates.year("my.employee.birthday", 1986)
The hour predicate checks that the value in the path occurs within the hour value passed into the predicate.
This uses the 24 hour system, starting at 0 and going through 23.
Note that this predicate will technically work for a Date field, but won’t be very useful. All date field values are automatically given an hour of 0.
Prismic::Predicates.hour( path, hour )
path
accepted paths
document.first_publication_date
document.last_publication_date
my.{custom-type}.{field}
hour
integer
Hour between 0 and 23
Examples:
Prismic::Predicates.hour("document.first_publication_date", 12)
Prismic::Predicates.hour("document.last_publication_date", 8)
Prismic::Predicates.hour("my.event.date-and-time", 19)
The hour_after predicate checks that the value in the path occurs after the hour value passed into the predicate.
This uses the 24 hour system, starting at 0 and going through 23.
Note that this will only return documents where the timestamp is after the specified hour. It will not return any documents where the timestamp is within the specified hour.
This predicate will technically work for a Date field, but won’t be very useful. All date field values are automatically given an hour of 0.
Prismic::Predicates.hour_after( path, hour )
path
accepted paths
document.first_publication_date
document.last_publication_date
my.{custom-type}.{field}
hour
integer
Hour between 0 and 23
Examples:
Prismic::Predicates.hour_after("document.first_publication_date", 21)
Prismic::Predicates.hour_after("document.last_publication_date", 8)
Prismic::Predicates.hour_after("my.blog-post.releaseDate", 16)
The hour_before predicate checks that the value in the path occurs before the hour value passed into the predicate.
This uses the 24 hour system, starting at 0 and going through 23.
Note that this will only return documents where the timestamp is before the specified hour. It will not return any documents where the timestamp is within the specified hour.
This predicate will technically work for a Date field, but won’t be very useful. All date field values are automatically given an hour of 0.
Prismic::Predicates.hour_before( path, hour )
path
accepted paths
document.first_publication_date
document.last_publication_date
my.{custom-type}.{field}
hour
integer
Hour between 0 and 23
Examples:
Prismic::Predicates.hour_before("document.first_publication_date", 10)
Prismic::Predicates.hour_before("document.last_publication_date", 14)
Prismic::Predicates.hour_before("my.event.dateAndTime", 12)