I'm trying to filter using todays date using this query below

var RestUrl = _spPageContextInfo.webAbsoluteUrl + "/_api/Web/Lists/GetByTitle('XXX')/items?$select=id,Title,Body,Image,Created,LinkToArticle,Author/Name,Author/Title&$expand=Author/Id&$orderby=Created desc&$filter=Created eq datetime'" + today.toISOString() + "'"; 

Using this query it seems not work. Any idea

  • What is the issue you're experiencing with this query? Is there an error returned? What is the value of the variable "today" in the query? Sep 13, 2017 at 7:01
  • Thanks Ornery.THe today string i'm using is good. As you can see its toISOString (today.toISOString()).Its just not working as i guess its a limitation with rest
    – naijacoder
    Sep 13, 2017 at 11:26

2 Answers 2


There is no limitation to the REST API in SharePoint Online that would prevent you from filtering on a date. Without more details about the code and any errors produced, it is difficult to troubleshoot. Here's a couple things to check:

  1. When expanding Author, simply use the "Author" field, not Author/Id. Author/Id should be in your select parameter if you would like that returned. (E.g. ?$select=Author/ID,Author/Name,Author/Title&$expand=Author)
  2. If the "today" variable is set to "new Date()", your query will only return items created at the current second instead of the current day. You will need today's date without time in ISO format, and then use the greater than or equal to (ge) operator in your filter.

You can use the following code to set the "today" variable to the start of the day and format your query:

var today = new Date();

var RestUrl = _spPageContextInfo.webAbsoluteUrl + "/_api/Web/Lists/GetByTitle('XXX')/items?$select=id,Title,Body,Image,Created,LinkToArticle,Author/Name,Author/Title,Author/Id&$expand=Author&$orderby=Created desc&$filter=Created ge datetime'" + today.toISOString() + "'";

Hope this helps!

  • Thanks Ornery.I had a different solution but yes it worked. I was trying to use this $filter=PublishedMonth eq 9 to filter by month (PublishedMonth is a calculated column) but getting error :-Calculated' cannot be used in the query filter expression
    – naijacoder
    Sep 14, 2017 at 4:57

Use the date value like EndTime le datetime'2013-06-12' Note: You may need to useListData.svc if you are on SP 2013.

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'

For Reference Check.

  • Thanks China.I'm on SP Online and using API.Could this be the reason its not working
    – naijacoder
    Sep 13, 2017 at 11:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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