I have a caml query filter for one of my date-time field.
<Leq> <FieldRef Name ='StartDate1' /> <Value Type ='DateTime'> <Today /> </Value> </Leq>
Is there anything same for rest api filter also?
StartDate1 leq ?
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It only takes a minute to sign up.Sign up to join this community
Use the date value like
EndTime le datetime'2013-06-12'
Note: You may need to use
ListData.svc if you are on SP 2013.
I started with turning on Team Collaboration Lists feature on my publishing site and creating the Calendar list. Then I have got my REST endpoint, this time around with a "greater than or equal to" filter:
http://devserver2012/_api/web/lists/getbytitle('events')/items?$select=Id,Title,Description,EventDate,EndDate,fAllDayEvent&$filter=EventDate ge datetime'2013-06-08T00:00:00'The reason for my blog post is that the above RESTful call doesn't work. Research has pointed out a few things: I am not the only one. Other people have had the issue. Rob Windsor's comment was quite useful to me. The MSDN guidance has a table of supported filtering operations. First of all, it incorrectly capitalizes the numeric comparison operations. For example, instead of "Ge" operator which does not work, I was using "ge" which does work. Second of all, the references pointing back at www.odata.org were unfortunately broken there, at the time of this writing at least. Later I've learned that my filter actually works with a Boolean "and" operator as I will show below. Does this make it unsupported? It probably does, according to the mentioned MSDN article, although the article itself clearly needs a revision. OData documentation is your friend. I find it hard to read, yet it is ultimately helpful. You can see query options supported by OData in section 4.5 on this page. Notice how the operators are all lowercase in the examples. The formatting of dates in filter queries can be found here. This is where the datetime'2013-06-08T00:00:00' comes from. One interesting detail, although the format spec does not indicate this, the following works just as well: datetime'2013-06-08T00:00:00Z'. Apparently the ISO-8601 is still honored. Getting back to my original REST call - what "fixes" it? If I were to use ListData.svc instead then I'd get the following:
http://devserver2012/_vti_bin/ListData.svc/Events?$select=Id,Title,StartTime,EndTime,AllDayEvent&$filter=StartTime > ge datetime'2013-06-10' and EndTime lt datetime'2013-06-12'