1

I am trying to get data from SharePoint list with REST API that are created today only.

var listName = "Carousel%20News";
var today = new Date().toISOString();

Here is my REST URL :

_spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/getbytitle('" + listName + "')/items?$select=Id,Title&$filter=Created eq '" + today + "'";

But when I use this rest URL, I am not getting the items that are created today.

(I have double checked that there are items present in the list with the today's created date)

My assumption is that, this URL filters based on Date and also Time value.

So is there way that I can use REST filter with today's date only and ignore the time stamp (like we do IncludeTimeValue=False in CAML query)?

0

For filtering date values add datetime in filter

var listName = "Carousel%20News";
var today = new Date();
var nextday  = moment(today).add(1,'days');

today = moment(today).format("YYYY-MM-DD");
var currentDate = today+'T00:00:00.000Z';

nextday = moment(nextday).format("YYYY-MM-DD");
var nextDate = nextday+'T00:00:00.000Z';
_spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/getbytitle('" + listName + "')/items?$select=Id,Title&$filter=Created ge datetime'" +currentDate+ "' and Created le datetime'" +nextDate+ "'";

I think this will solve the problem
Note: Refer moment.js for next day
Check this in your browser SITE_URL/_api/web/lists/getbytitle('LISTNAME')/items?$select=Id,Title&$filter=Created ge datetime'2017-09-14T00:00:00.000Z'

  • I already tried using datetime. But it didn't solve my problem :) – Rohit Waghela Sep 14 '17 at 12:06
  • updated answer its working for me – Vishnu S Sep 14 '17 at 12:37

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.