最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to filter oData call using dynamic date? - Stack Overflow

programmeradmin7浏览0评论

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

http://someputer/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.

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

http://someputer/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.

Share Improve this question asked Aug 24, 2014 at 11:14 Konrad VilterstenKonrad Viltersten 39.3k85 gold badges287 silver badges509 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 3

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.

Yes, of course. One example:

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

评论列表(0)

  1. 暂无评论