3

I'm using the on prem SharePoint 2013 REST API and I'm getting an error when I try to compare two date fields.

$filter=ExpectedDelivery gt NeededBy

The above query works perfectly using ListData.svc. Any suggestions for the _api endpoint?

Please note that this likely will not be duplicated on an O365 SP site as I have repeatedly established that the O365 REST API does not behave the same as the on prem version regarding date filtering. <= I still get that error too!

Here is my build information:

Major  Minor  Build  Revision
-----  -----  -----  --------
15     0      4569   1000

EDIT

I tried the calculated column route but that was no help as you cannot do a filter via REST on calculated fields. As a result, I am currently just going to get all items that match the minimum criteria and then use client side filtering on the rest. It is really sad that SharePoint 2013's REST is lacking in some of the most basic features that would make it highly robust. The ability to not filter on nulls unless you POST a CAML query or to not be able to do simple gt or lt on two date fields is just mind boggling.

1

Date Time operations just like filtering for a date time is not supported. I tried it in many ways and never had a luck. You have to stay with the listdata.svc for that.

Check out this post by Microsoft

http://msdn.microsoft.com/EN-US/library/office/fp142385(v=office.15).aspx

You will find all supported and unsupported OData query operations.

Date and time functions

Supported:

  • day()
  • month()
  • year()
  • hour()
  • minute()
  • second()

Unsupported

  • DateTimeRangesOverlap operator
  • Querying as to whether a date time falls inside a recurrent date time pattern
| improve this answer | |
0

I was able to get the filtering working by using datetime prefix in SharePoint Online (Office 365). Here is an example of a REST query that pulls the dates back in a range.

_api/web/lists/getbytitle('Expenses')/Items?$filter=Expense_x0020_Date ge datetime'2015-04-06T00:00:00Z' and Expense_x0020_Date le datetime'2015-04-07T00:00:00Z'

Here are the supported operators:

https://msdn.microsoft.com/EN-US/library/office/fp142385(v=office.15).aspx#bk_supported

In your case I would try:

$filter=ExpectedDelivery Gt datetime'NeededBy'
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.