0

Background:

In Sharepoint Online, I'm using the Sharepoint REST API for query a few records based on its creation date (column Created).

I'm using the following variations of the REST query for get the items created in a range of time:

Variation #1 - has this datetime format: dd/MM/yyyy.

https:///_api/web/lists/GetByTitle('LIST_NAME')/items?&$select=Created&$filter=Created ge '2016-05-01T00:00:00Z' and Created le '2016-05-04T00:00:00Z'&$orderby=Created desc

Variation #2:

https:///_api/web/lists/GetByTitle('LIST_NAME')/items?&$select=Created&$filter=Created ge '01/05/2016 00:00' and Created le '04/05/2016 00:00'&$orderby=Created desc

Problem:

I'm waiting that those queries brings me the created data in that lapse of time, But none of them doesn't return any data.

Only when I add one more day to the datetime range, (i.e):

Variation #1 - has this datetime format: dd/MM/yyyy.

https:///_api/web/lists/GetByTitle('LIST_NAME')/items?&$select=Created&$filter=Created ge '2016-05-01T00:00:00Z' and Created le '2016-05-05T00:00:00Z'&$orderby=Created desc

Variation #2:

https:///_api/web/lists/GetByTitle('LIST_NAME')/items?&$select=Created&$filter=Created ge '01/05/2016 00:00' and Created le '05/05/2016 00:00'&$orderby=Created desc

The query returns me the data that should be queried using the datetime range in previous lines.

Here is the results:

2016-05-04T22:45:16Z

2016-05-04T22:36:29Z

2016-05-04T15:32:59Z

2016-05-04T15:07:24Z

This is a screenshot which shows the current data available:

enter image description here

I check these related questions, but none of them solves my current problem.

What could be the cause of this situation?

0

It seems that the problem was the formatting of string value as a valid SharePoint datetime.

wjervis's comment is right; I have to adapt my source code for get the selected date "hour and minutes" in my form and using the toISOString method.

So, if I need datetime with the ISO 8601 format; I use the following code:

// This is the date that I select in my form: "26/05/2016 17:00".

// I separate the previous string and create a new Date object:
var myDate = new Date(2016, 4, 26, 17, 0);

// With this line, I can use later in the query (using the SharePoint REST API).
var ISO_FormattedDate = myDate.toISOString();

The result is:

2016-05-26T22:00:00.000Z

And modifying the query as follows:

https://<SITE_NAME>/_api/web/lists/GetByTitle('LIST_NAME')/items?&$select=Created&$filter=Created ge '2016-05-26T22:00:00.000Z' and Created le '2016-05-26T23:00:00.000Z'&$orderby=Created desc

I finally could get the expected results.

  • 1
    SharePoint expects the date to be in ISO 8601 format – wjervis May 24 '16 at 17:46

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.