简体   繁体   English

Sharepoint的CAML查询中的日期时间比较

[英]Datetime comparison in CAML Query for Sharepoint

i'm trying to have some item from a sharepoint list, depends on date in a custom column. 我正在尝试从sharepoint列表中获取某些项目,具体取决于自定义列中的日期。

I've created my query with U2U Caml Builder, and that's worked but when I put it in my own code in my webpart, it always return to me all the items od the list. 我已经使用U2U Caml Builder创建了我的查询,这是有效的,但是当我把它放在我自己的webpart中的代码中时,它总是返回给我列表中的所有项目。

Here is my code: 这是我的代码:

DateTime startDate = new DateTime(Int32.Parse(year), 1, 1);
            DateTime endDate = new DateTime(Int32.Parse(year), 12, 31);
            SPQuery q = new SPQuery();
            q.Query = "<Query><Where><And><Geq><FieldRef Name='Publicate Date' /><Value IncludeTimeValue='FALSE' Type='DateTime'>" + SPUtility.CreateISO8601DateTimeFromSystemDateTime(startDate) + "</Value></Geq><Leq><FieldRef Name='Publicate_x0020_Date' /><Value IncludeTimeValue='FALSE' Type='DateTime'>" + SPUtility.CreateISO8601DateTimeFromSystemDateTime(endDate) + "</Value></Leq></And></Where></Query>";

            SPListItemCollection allItem = library.GetItems(q);

You don't need the <Query> tag. 您不需要<Query>标记。 That's why you query isn't being executed. 这就是你没有执行查询的原因。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM