Query by date

Query by an exact date

You can query by date fields the same way as you do it in case of other field types. The only difference is that the value should be a date string that match the format YYYY-MM-DD HH:mm:ss.

The following example returns the content that was created on the 15th of february 2019:

Copy
https://dev.demo.sensenet.com/OData.svc/Root/Content?query=CreationDate%3A'2019-02-15'

// the special characters should be url encoded
// the actual query here is ?query=CreationDate:'2019-02-15'

The next query is an example that shows you how to get the event contents that start at 05.05.2019 9:30 pm (CalendarEvent contents thats' StartDate's value is the given one)

Copy
https://dev.demo.sensenet.com/OData.svc/Root/Content?query=StartDate%3A'2019-02-15 09%3A30%3A00'

// the special characters should be url encoded
// the actual query here is ?query=StartDate:'2019-02-15 09:30:00'

Query before or after a specific date

You can also use operators in queries by date fields to search before or after a certain date.

Following query returns with the list of contents created before 10th of january 2019:

Copy
https://dev.demo.sensenet.com/OData.svc/Root/Content?query=CreationDate%3A<'2019-01-10'

// the special characters should be url encoded
// the actual query here is ?query=CreationDate:<'2019-01-10'

Next example returns the contents modified since 10th of january 2019:

Copy
https://dev.demo.sensenet.com/OData.svc/Root/Content?query=ModificationDate%3A>'2019-01-10'

// the special characters should be url encoded
// the actual query here is ?query=ModificationDate:>'2019-01-10'

Query by a date range

Range queries allow you to query contents thats' field(s) values are between the given lower and upper bound specified by the query. Range queries can be inclusive or exclusive at the upper and lower bounds (inclusiveness is given by square brackets [] and exclusiveness by curly brackets {}). As you will see in the examples below, the two types can also be mixed.

The following example query returns contents created between the two given dates including the given first and last dates.

Copy
https://dev.demo.sensenet.com/OData.svc/Root/Content?query=CreationDate%3A{'2010-08-30' TO '2010-10-30'}

// the special characters should be url encoded
// the actual query here is ?query=CreationDate:{'2010-08-30' TO '2010-10-30'}

The following example query returns contents created between the two given dates excluding the given first and last dates.

Copy
https://dev.demo.sensenet.com/OData.svc/Root/Content?query=CreationDate%3A['2010-08-30' TO '2010-10-30']

// the special characters should be url encoded
// the actual query here is ?query=CreationDate:['2010-08-30' TO '2010-10-30']

The following example query returns contents created between the two given dates including the first and excluding the given last date.

Copy
https://dev.demo.sensenet.com/OData.svc/Root/Content?query=CreationDate%3A['2010-08-30' TO '2010-10-30'}

// the special characters should be url encoded
// the actual query here is ?query=CreationDate:['2010-08-30' TO '2010-10-30'}

Querying with dynamic template parameters

Using template parameters helps you to use dynamic values in queries. For further information and full list of the available template parameters see the related docs and for some date query related help see the following examples.

This query returns the contents modified yesterday:

Copy
https://dev.demo.sensenet.com/OData.svc/Root/Content?query=ModificationDate%3A@Yesterday@

// the special characters should be url encoded
// the actual query here is ?query=ModificationDate:@Yesterday@

Following example shows how to get the list of next month's event contents:

Copy
https://dev.demo.sensenet.com/OData.svc/Root/Content?query=StartDate%3A>@NextMonth@

// the special characters should be url encoded
// the actual query here is ?query=StartDate:>@NextMonth@

The following query returns the list of contents created in the last year:

Copy
https://dev.demo.sensenet.com/OData.svc/Root/Content?query=CreationDate%3A@PreviousYear@

// the special characters should be url encoded
// the actual query here is ?query=CreationDate:@PreviousYear@

Query by lifespan validity

In some content management scenarios contents have lifespan information. This means the content is created but will be valid or available only on a defined date in the future and it may become invalid on another date. See lifespan in details in the related doc at the API basic concepts.

Lifespan filtering is turned off by default. If you want to get results depending on the lifespan status of content (value of its ValidFrom and ValidTill fields), you can switch this filter on in your query as you can see in the following example:

Copy
https://dev.demo.sensenet.com/OData.svc/Root/Content?query=TypeIs%3AArticle .LIFESPAN%3AON

// the special characters should be url encoded
// the actual query here is ?query=TypeIs:Article .LIFESPAN:ON