我在写一个 SPSiteDataQuery 而且我对 Query 财产。我需要返回所有结果 Record_x0020_Yr_x0020_End_x0020_Date 在本年度的12/31之间,在90天之前。

示例:如果我现在运行此查询,我应该将所有项目放在9/31/2011-12/31/2011之间。如果我明年的任何时候都进行了查询,我应该得到9/31/2012-12/31/2012。到目前为止,这就是我所拥有的:

query.Query = string.Format(@"
<Where>
    <Eq>
        <FieldRef Name='Record_x0020_Yr_x0020_End_x0020_Date' />
        <Value Type='DateTime' IncludeTimeValue='FALSE'>{0}</Value>
    </Eq>
</Where>", new DateTime(DateTime.Now.Year, 12, 31).ToString("yyyy-MM-dd"));

这给了我所有日期在今年年底的人,但是我该如何添加范围?

有帮助吗?

解决方案

下载 CAML查询构建器工具,例如U2U 帮助您正确获取语法。

使用该工具,这是我开始的开始日期> = 1/jan/2011和StartDate <= 31/dec/2011-您可以将其调整为列表列和日期范围。

<Query>
  <Where>
    <And>
      <Geq>
        <FieldRef Name="StartDate" />
          <Value IncludeTimeValue="TRUE" Type="DateTime">2011-01-01T15:55:52Z</Value>
      </Geq>
      <Leq>
        <FieldRef Name="StartDate" />
        <Value IncludeTimeValue="TRUE" Type="DateTime">2011-12-31T15:56:29Z</Value>
      </Leq>
    </And>
  </Where>
</Query>

其他提示

看一下这个:

http://social.msdn.microsoft.com/forums/en-us/sharepointdevelopment/thread/076c57b1-a780-4b86-b86-b00b-849fa87878789318

您的两个日期:

DateTime lastDay = new DateTime(DateTime.Now.Year, 12, 31);
DateTime dtThreeMonthsPrior = lastDay.AddMonths(-3);

另外,在您的问题中,您提到的日期是9/31,这是无效的,因为第9个月只有30天。

许可以下: CC-BY-SA归因
scroll top