I think above will not work because it is taking into consideration time component, you have to ignore time component and compare only date to get value. There is no straight forward way to do this. You have to use below
Logic is to compare Today date with current date(starting from first second) and tommorow(starting from first second)
Add below function to create custom addDays
Date.prototype.addDays = function(days) {
var date = new Date(this.valueOf());
date.setDate(date.getDate() + days);
return date;
}
var today = new Date();
var Startdate = today.toISOString().substring(0,10) + "T00:00:00.000Z";
var Enddate = today.addDays(1).toISOString().substring(0,10) + "T00:00:00.000Z";
var queryString = "$filter=Today le datetime'" + Enddate + "'and Today ge datetime'" + Startdate + "'";
jQuery.ajax({
url: encodeURI(_spPageContextInfo.webServerRelativeUrl + "/_api/web/lists/getbytitle('" + listName + "')/items?" + queryString),
type: "GET",
headers: {
"Accept": "application/json; odata=verbose",
"Content-Type": "application/json;odata=verbose",
}
}).done(function (data) { console.log(data.d.results})
Add &$Top=1 to queryString if you want to retrieve only 1 single item(please note it will return top item only with order by created date ascending order. You can specify order by desc to retrieve last item.
Date.prototype.addDays = function(days) { var date = new Date(this.valueOf()); date.setDate(date.getDate() + days); return date; } Is this how i have to add the code? Iam getting an error in class Promise
A function whose declared type is neither 'void' nor 'any' must return a value.ts(2355)
– Selvin Jun 25 '19 at 04:55