OData query filter for dateTime range

帅比萌擦擦* 提交于 2019-12-05 16:33:06

问题


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.


回答1:


$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




回答2:


In OData V4 date filtering format has changed, the correct filter will be

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

For example

http://services.odata.org/V4/OData/OData.svc/Products?%24filter=ReleaseDate%20gt%201995-09-01T00:00:00Z%20and%20ReleaseDate%20lt%201995-12-01T00:00:00Z

For previous versions of OData see previous answer




回答3:


Breeze will automatically construct an OData filter under the covers for any query. So to query for a date will look something like this in Breeze.

var query = new EntityQuery("Orders")
        .where("orderDate", ">", new Date(1998, 3, 1));


来源:https://stackoverflow.com/questions/24489458/odata-query-filter-for-datetime-range

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!