Monday, September 12, 2016

How to filter SharePoint list Based in Date Time related functions in SharePoint 2013 using REST/ODATA

REST queries are quiet familiar when you are working with SharePoint Apps and SharePoint development.

I have found quiet difficult to pass the Date Time parameter to REST and took few minutes to figure that out.

There are two ways to end points to access list data.

http://<SharePoint Url>/_api/web/lists/getbytitle('Pages')/items?

http:// <SharePoint Url>/_vti_bin/listdata.svc

And these functions are working only on listdata.svc

These are few example of REST queries which uses Created Column as a sample field.

 

Filter using day () function

http:// <SharePoint Url>/_vti_bin/listdata.svc/<listname>?$filter = day(Created) eq 2

 

Filter using month () function

http:// <SharePoint Url>/_vti_bin/listdata.svc/<listname>?$filter = month (Created) eq 2

 

Filter using year () function

http:// <SharePoint Url>/_vti_bin/listdata.svc/<listname>?$filter = year (Created) eq 2

 

Filter using hour () function

http:// <SharePoint Url>/_vti_bin/listdata.svc/<listname>?$filter = hour (Created) eq 2

 

Filter using minute () function

http:// <SharePoint Url>/_vti_bin/listdata.svc/<listname>?$filter = minute (Created) eq 2

 

Filter using second () function

http:// <SharePoint Url>/_vti_bin/listdata.svc/<listname>?$filter = second (Created) eq 2

Post a Comment