Wednesday, December 9, 2015

How to filter List Items based on Date Time using REST in SharePoint Online

Hi All,

If you have requirement to filter data from a SharePoint Online List based on "fromdate" and "todate" using REST - please use below code

var fromDate=$("#txtdate").val();

var toDate=$("txttodate").val();

var url = _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/getbytitle('" + ListName + "')/items?" +
                                "$select=ID,Title,DateOfEntry,Hours,Comments,AuthorId,Author/Title" +
                              "&$filter=DateOfEntry ge datetime'" + fromDate + "' and DateOfEntry le datetime'" + toDate + "' &$expand=Author/Title";
                $.ajax({
                    url: url,
                    type: "GET",
                    headers: { "accept": "application/json;odata=verbose", },
                    success: function (data) {
                        var results=  data.d.results;
                       //do whatever u want
                           
                        }

                    },
                    error: function (xhr) {
                        alert(xhr.status + ': ' + xhr.statusText);
                        console.log(xhr.status + ': ' + xhr.statusText);
                    }
                });


by Pankaj Srivastava via Everyone's Blog Posts - SharePoint Community

No comments:

Post a Comment