[英]How to filter oData call using dynamic date?
I'm making an AJAX call using URL as follows. 我正在使用URL进行AJAX调用,如下所示。
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. 这非常有效,而且在我的AJAX调用之前,我生成了描述日期的字符串。 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. 我在google搜索时没有找到任何相关的文档,所以可能不可能,但我仍然需要检查SO的智慧。
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 + "'";
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.
OData中有内置查询函数 ,您可以在查询选项中使用它来表示动态值。 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. 从链接中可以看到在“日期函数”类别下存在此函数
now()
,并且ODataLib已在其最新版本的URL解析器中支持它。 (see the release notes here ). (参见此处的发行说明)。
But there are two things for you to note: 但是有两件事需要注意:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.