我想从SPList
检索日期范围内的项目。开始日期为今天,结束日期为自今天起30天后的第二天。这是我的CAML查询。
query.Query = string.Concat(@
"<Where>
<And>
<Geq>
<FieldRef Name='EventDate' />
<Value IncludeTimeValue='False' Type='DateTime'><Today /></Value>
</Geq>
<Leq>
<FieldRef Name='EventDate' />
<Value IncludeTimeValue='False' Type='DateTime'><Today offset='30'/></Value>
</Leq>
</And>
</Where>
<OrderBy>
<FieldRef Name='EventDate' Ascending='True' />
</OrderBy>");
SPListItemCollection items = list.GetItems(query);
但这只会返回具有今天日期的项目。
答案 0 :(得分:1)
在OffsetDays
值中使用Offset
或offset
而非<Today/>
尝试此操作...
query.Query = string.Concat(@
"<Where>
<And>
<Geq>
<FieldRef Name='EventDate' />
<Value IncludeTimeValue='False' Type='DateTime'><Today /></Value>
</Geq>
<Leq>
<FieldRef Name='EventDate' />
<Value IncludeTimeValue='False' Type='DateTime'><Today OffsetDays='30'/></Value>
</Leq>
</And>
</Where>
<OrderBy>
<FieldRef Name='EventDate' Ascending='True' />
</OrderBy>");
What is the difference between CAML Offset and OffsetDays?
或者,您可以创建DateTime
个对象并使用SPUtility.CreateISO8601DateTimeFromSystemDateTime method