OData query filter for dateTime range

user2439903 picture user2439903 · Jun 30, 2014 · Viewed 45.5k times · Source

I have a DateTime property in the data returned by a service that looks like "SDateTime":"2014-06-29T03:30:00.000".

I need to write a query to get a collection which has the date less than "2014-06-26T03:30:00.000" and greater than "2014-06-23T03:30:00.000"

How to write a filter for the dateTime?

Thanks.

Answer

Tan Jinfu picture Tan Jinfu · Jun 30, 2014

$filter=SDateTime gt datetime'2014-06-26T03:30:00.000' and SDateTime lt datetime'2014-06-23T03:30:00.000'

It works in this service: http://services.odata.org/V3/OData/OData.svc/Products?$filter=ReleaseDate%20gt%20datetime%271995-09-01T00:00:00%27%20and%20ReleaseDate%20lt%20datetime%271995-12-01T00:00:00%27