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


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.


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


You will find all supported and unsupported OData query operations.

Date and time functions


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


  • DateTimeRangesOverlap operator
  • Querying as to whether a date time falls inside a recurrent date time pattern

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:


In your case I would try:

$filter=ExpectedDelivery Gt datetime'NeededBy'

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.