Sharepoint - Filter Created in SP REST API
SharePoint REST API endpoints take ISO formatted date string for filtering.
Try using below query for filtering on Date Field:
- To check greater than
2018/10/05
:
https://[tentat]/sites/[site]/Normativo/ComunicacoesDeNegocio/_api/web/lists('e97f928b-34e4-34e2-c2c7-150ea469fac3')/items?$select=ID,Title,Created,QuemLeu/Id&$expand=QuemLeu&$filter=(Created gt datetime'2018-10-05T00:00:00Z')
- To check greater than or equal to
2018/10/05
:
https://[tentat]/sites/[site]/Normativo/ComunicacoesDeNegocio/_api/web/lists('e97f928b-34e4-34e2-c2c7-150ea469fac3')/items?$select=ID,Title,Created,QuemLeu/Id&$expand=QuemLeu&$filter=(Created ge datetime'2018-10-05T00:00:00Z')
Answer For Updated Question:
Add one more IF
statement inside if(data.d)
like given below:
if(data.d){
if(new Date(data.d.Created) > new Date("2018-10-05")) {
console.log("Items is created after '2018-10-05'");
} else {
console.log("Items is created before '2018-10-05'");
//Add your other code here
}
}
Add $filter
to your query and use Created gt datetime'2018-10-05T00:00:00'
or Created gt '2018-10-05'
/_api/web/lists('guid')/items?$select=ID,Title,Created,QuemLeu/Id&$expand=QuemLeu&$filter=Created gt '2018-10-05'
Just add
&$filter=Created gt '2018-10-05'
At the end of your endpoint
For example:
https://[tentat]/sites/[site]/Normativo/ComunicacoesDeNegocio/_api/web/lists('e97f928b-34e4-34e2-c2c7-150ea469fac3')/items('193')?$select=ID,Title,Created,QuemLeu/Id&$expand=QuemLeu&$filter=Created gt '2018-10-05'
Gt operator means "greater than"
And also you can check all operators below:
Lt (less than)
Le (less than or equal)
Gt (greater than)
Ge (greater than or equal)
Eq (equal to)
Ne (not equal to)