Sharepoint 的 CAML 查询中的日期时间比较 [英] Datetime comparison in CAML Query for Sharepoint
本文介绍了Sharepoint 的 CAML 查询中的日期时间比较的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试从共享点列表中获取一些项目,这取决于自定义列中的日期.
i'm trying to have some item from a sharepoint list, depends on date in a custom column.
我已经使用 U2U Caml Builder 创建了我的查询,这很有效,但是当我将它放在我自己的 webpart 代码中时,它总是返回给我列表中的所有项目.
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.
这是我的代码:
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. That's why you query isn't being executed.
这篇关于Sharepoint 的 CAML 查询中的日期时间比较的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文