Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I am trying to filter standard Calendar events via SharePoint web api and my query looks like this:

/_api/web/lists/getbytitle('calendar')/items?$filter=( EventDate  ge  datetime'2013-01-26T22:00:00Z')&$select=Title,EventDate,ID 

Query doesn't work and I receive this error:

The field 'EventDate' of type 'DateTime' cannot be used in the query filter expression

Error Details:

{"error":{"code":"-1, Microsoft.SharePoint.SPException","message":{"lang":"en-US","value":"The field 'EventDate' of type 'DateTime' cannot be used in the query filter expression."},"innererror":{"message":"The field 'EventDate' of type 'DateTime' cannot be used in the query filter expression.","type":"Microsoft.SharePoint.SPException","stacktrace":"   at Microsoft.SharePoint.SPListItemEntityCollectionCamlQueryBuilder.CheckFieldRefUsage(SPField field, FieldRefUsage fieldRefUsage)\r\n   at Microsoft.SharePoint.SPListItemEntityCollectionCamlQueryBuilder.SetFieldRef(XmlWriter writer, String fieldPath, FieldRefUsage fieldRefUsage, Action`1 attributeAction)\r\n   at Microsoft.SharePoint.SPListItemEntityCollectionCamlQueryBuilder.SetWhereBinaryOp(XmlWriter writer, EdmParserNode parseNode)\r\n   at Microsoft.SharePoint.SPListItemEntityCollectionCamlQueryBuilder.SetViewQuery(SPQuery query, XmlWriter writer, StringBuilder sb)\r\n   at Microsoft.SharePoint.SPListItemEntityCollectionCamlQueryBuilder.BuildCamlQuery()\r\n   at Microsoft.SharePoint.SPListItemEntityCollectionCamlQueryBuilder..ctor(SPList list, RESTfulQuery restQuery, Nullable`1 itemId)\r\n   at Microsoft.SharePoint.SPListItemEntityCollection.TryWriteAsOData(ODataWriter writer, RESTfulQuery query, ProxyContext proxyContext)\r\n   at Microsoft.SharePoint.Client.ServerStub.Write(Object value, Uri path, ODataWriter writer, RESTfulQuery query, ProxyContext proxyContext)\r\n   at Microsoft.SharePoint.Client.Rest.RestRequestProcessor.Process()\r\n   at Microsoft.SharePoint.Client.Rest.RestRequestProcessor.ProcessRequest()\r\n   at Microsoft.SharePoint.Client.Rest.RestService.ProcessQuery(Stream inputStream, IList`1 pendingDisposableContainer)","internalexception":{"message":"The field 'EventDate' of type 'DateTime' cannot be used in the query filter expression.","type":"Microsoft.SharePoint.Client.InvalidClientQueryException","stacktrace":""}}}}

Is it possible somehow to use fields type of DateTime in filter query expressions?

Update: I found that I can do this via ListData.svc, e.g.

/_vti_bin/ListData.svc/Calendar?$filter=StartTime+ge+datetime'2011-11-23'

More details here - http://itblog.wolthaus.net/2011/12/rest-filter-datetime/

I tried to remove the time part from the /_api/web/ query, e.g.

/_api/web/lists/getbytitle('calendar')/items?$filter=( EventDate  ge  '2013-01-26')&$select=Title,EventDate,ID

But it didn't help and I got the same error.

These queries below don't work:

Query 1:

_api/web/lists/getbytitle('calendar')/items?$filter=( EventDate  ge datetime'2013-01-26T22:00:00Z')&$select=Title,EventDate,ID

OR

/_api/web/lists/getbytitle('calendar')/items?$filter=( EventDate  ge '2013-01-26')&$select=Title,EventDate,ID

Error:

The field 'EventDate' of type 'DateTime' cannot be used in the query filter expression

Query 2:

_api/web/lists/getbytitle('calendar')/items?$filter=( EventDate  ge datetime'2013-01-26')&$select=Title,EventDate,ID

Error:

The expression "( EventDate ge datetime'2013-01-26')" is not valid
share|improve this question
    
SharePoint version please? –  Robert Kaucher Apr 12 '13 at 19:01
add comment

1 Answer

You actually have the answer in your question. In your update you show:

/_vti_bin/ListData.svc/Calendar?$filter=StartTime+ge+datetime'2011-11-23'

Notice the string with the date is prefaced by datetime. You just need to do the same thing in the query you are trying to write.

http://www.odata.org/documentation/overview#AbstractTypeSystem

share|improve this answer
    
no, it doesn't work for /_api/web query. added these queries to my question. thank you! –  Sergey Feb 13 '13 at 15:29
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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