How to filter oData call using dynamic date?

这一生的挚爱 提交于 2019-12-11 11:40:27

问题


I'm making an AJAX call using URL as follows.

http://somecomputer/Service.svc/Method?$filter=SomeDate gt DateTime'2014-08-24'

This works perfectly and and the moment, I generate the string describing the date right before my AJAX call. However, I wonder if it's possible to match the date on dynamic values, such as today or lastyear or what not.

I haven't found any documentation of that when googling so probably it's not possible but I still need to check with the wisdom of SO.


回答1:


Yes, it is possible. There is such thing as Built-in Query Functions in OData that you can use in query options to represent dynamic values. From the link you can see that there is this function now() under the "Date Functions" category and the ODataLib has already supported it in the URL parser of its latest version. (see the release notes here).

But there are two things for you to note:

  1. ODataLib only deals with the parsing of such functions in request URLs, the actual logic of it needs to be further implemented by the service implementers.
  2. According to the look up of the OData V3 protocol (section 10.2.3.1.2 on this page), V3 doesn't have such dynamic built-in query functions.



回答2:


Yes, of course. One example:

var today = new Date().toISOString().substr(0,10);
var url = "http://somecomputer/Service.svc/Method?"
  + "$filter=SomeDate gt DateTime'" + today + "'";


来源:https://stackoverflow.com/questions/25471104/how-to-filter-odata-call-using-dynamic-date

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