1

I need to retrieve items from a SP List based on the Date_of_Event.

I want all items in the list which occurred the last month.

How does my request looks like?

var urlForOrderBy = "/_api/Web/Lists/GetByTitle('OIE Alerts')/Items?" +
    "$select=ID,Title,Country,Date_of_Event,LandCode," + .......
    &$orderby=Date_of_Event desc";
1

I solved the question.

var urlForAllItems = "/_api/Web/Lists/GetByTitle('OIE Alerts')/Items?" +
"$select=Title,Date_x0020_of_x0020_Event,Country0/Title,Country0/Column2&$expand=Country0&" +
 "$filter=Date_x0020_of_x0020_Event gt '"+startDate+"'&$orderby=Date_x0020_of_x0020_Event desc";
1

Something like:

var today = new Date();
var lastmonth = today.setMonth(today.getMonth()-1);

var urlForOrderBy = "/_api/Web/Lists/GetByTitle('OIE Alerts')/Items?" +
 "$select=ID,Title,Country,Date_of_Event,LandCode," + 
 "$filter=Date_of_Event gt " + lastmonth.toISOString() + 
 "&$orderby=Date_of_Event desc";
  • Mike, does that use the previous month or really the last 30 days? for example when it is 30 oct, will it include all events from 1 sep until 30 oct? – Marco Nov 3 '17 at 12:47
  • see my edit--changed it to your requirements – Mike Nov 3 '17 at 13:57
  • Mike, thanks for the update. I hope I explained myself clearly in English :) because what I wanted is using the date of today and up until max 30 days before that. For example events between 3 oct and 3 nov (today). – Marco Nov 3 '17 at 14:04
  • then it was how I had it before. Let me change it back. This is get all events within the last month. So from October 3rd through November 3rd. – Mike Nov 3 '17 at 16:53
  • Sorry for being not clear – Marco Nov 3 '17 at 17:01

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.