Skip to main content
replaced http://sharepoint.stackexchange.com/ with https://sharepoint.stackexchange.com/
Source Link

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

wjervis's commentwjervis'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.

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.

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.

Updated question.
Source Link

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

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

01/05/2016 08:10

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

var// nDateThis =is null;
varthe string_datedate =that "01I select in my form: "26/05/2016 0817:10";00".
nDate
// I separate the previous string and create a new Date object:
var myDate = new Date(string_date.split('/')[2]2016, (string_date.split('/')[1]-1)4, string_date.split('/')[0]26, string_date.split('17, ')[1].split(':'0)[0];

// With this line, string_date.splitI can use later in the query ('using 'the SharePoint REST API)[1].split(':')[1]);
string_datevar ISO_FormattedDate = $SP()myDate.toSPDatetoISOString(nDate, true);

The result is:

2016-05-04 0826T22:1000: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-01 0026T22:00:00'00.000Z' and Created le '2016-05-04 2326T23:5900:00'&$orderby=Created00.000Z'&$orderby=Created desc

I finally could get the expected results.

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

After convert the following string value:

01/05/2016 08:10

Using the following code:

var nDate = null;
var string_date = "01/05/2016 08:10";
nDate = new Date(string_date.split('/')[2], (string_date.split('/')[1]-1), string_date.split('/')[0], string_date.split(' ')[1].split(':')[0], string_date.split(' ')[1].split(':')[1]);
string_date = $SP().toSPDate(nDate, true);

The result is:

2016-05-04 08:10:00

And modifying the query as follows:

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

I finally could get the expected results.

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.

Source Link

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

After convert the following string value:

01/05/2016 08:10

Using the following code:

var nDate = null;
var string_date = "01/05/2016 08:10";
nDate = new Date(string_date.split('/')[2], (string_date.split('/')[1]-1), string_date.split('/')[0], string_date.split(' ')[1].split(':')[0], string_date.split(' ')[1].split(':')[1]);
string_date = $SP().toSPDate(nDate, true);

The result is:

2016-05-04 08:10:00

And modifying the query as follows:

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

I finally could get the expected results.