SharePoint REST API过滤器仅基于今天的日期而非时间。(类似于CAML查询中的IncludeTimeValue = False)

Roh*_*ela 5 rest sharepoint-2013

我试图使用今天才创建的REST API从SharePoint列表中获取数据。

var listName = "Carousel%20News";
var today = new Date().toISOString();
Run Code Online (Sandbox Code Playgroud)

这是我的REST URL:

_spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/getbytitle('" + listName + "')/items?$select=Id,Title&$filter=Created eq '" + today + "'";
Run Code Online (Sandbox Code Playgroud)

但是,当我使用此剩余URL时,我没有得到今天创建的项目。

(我仔细检查了列表中是否存在具有今天创建日期的项目)

我的假设是,此URL根据日期和时间值进行过滤。

因此,有没有办法我可以仅将REST过滤器用于今天的日期,而忽略时间戳(就像我们IncludeTimeValue=False在CAML查询中所做的那样)?

bla*_*123 1

我不知道如何在 CAML 中得到这个。然而,我最近刚刚开始在下面执行此操作。我正在使用 $.ajax 查询和 for 循环来获取我的数据。

$(document).ready(function()
{
    var siteURL = _spPageContextInfo.webServerRelativeUrl;
    var listName = "Carousel%20News";
	  var url = siteURL + "/_api/web/lists/getbytitle('"+listName+"')/Items";
    $.ajax
    ({
      url: url,
			method: "GET",
			contentType: "application/json; odata=verbose",
			headers: { "Accept": "application/json; odata=verbose" },
			success: function (data)
      {
        var dateTime = new Date();
        var now = Date.parse(dateTime); //convert dateTime to milliseconds
        for (var i = 0; i < data.d.results.length; i++)
        {
          var item = data.d.results[i];
          var ID = item.ID;
          var Created = item.Created;
          /* Lets get the millisecond value for our Date/Time Column */
          var today = Date.parse(Created); //get Millisecond value for Created Date
          var createdDiff = now - today; // get the date difference between now and Created in Milliseconds
          var formatDateDiff = createdDiff/86400000;
          console.log("Item#: "+ID+", "+"Date Difference (24 hr)= "+formatDateDiff);
          
          //Lets only show the results that meet this criteria
          if(formatDateDiff <= 24){
            // do something with your code
          };
        }
      },
      error: function(data)
      {  
        //Give me an error
      }
  });
});
Run Code Online (Sandbox Code Playgroud)
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
Run Code Online (Sandbox Code Playgroud)

让我知道这是否解决了您的问题或帮助您走上正轨