Query by Date with .NET

Query by exact date

Here we show how to query documents for a Date field equal to a specific date.

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();

Other time-based predicates

Here are the other available Date query predicates.

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);

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
var response = await api
    .query(Predicates.at("document.type", "blog-post"))
    .orderings("my.blog-post.date")
    .Submit();