在CAML查询日期时间comparaison对于SharePoint [英] Datetime comparaison in CAML Query for Sharepoint
本文介绍了在CAML查询日期时间comparaison对于SharePoint的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图从SharePoint列表中有一些项目,取决于日期的自定义列。
我已经建立了我的查询与U2U CAML生成器, ,而这工作,但是当我把它放在我自己的代码在我的WebPart,它总是回到我所有的项目OD名单
下面是我的代码:
日期时间的startDate =新日期时间(Int32.Parse(年),1,1);
DateTime的结束日期=新的日期时间(Int32.Parse(年),12,31);
SPQuery Q =新SPQuery();
q.Query =<查询><其中><和>< GEQ>< FieldRef名称='Publicate日期/><值IncludeTimeValue =FALSE类型=日期时间 >中+ SPUtility.CreateISO8601DateTimeFromSystemDateTime(的startDate)+< /值>< / GEQ><等效声级>< FieldRef名称='Publicate_x0020_Date/><值IncludeTimeValue =FALSE类型='日期时间'>中+ SPUtility.CreateISO8601DateTimeFromSystemDateTime(结束日期)+< /价值与GT;< /等效声级>< /和>< /在哪里>< /查询>中;
SPListItemCollection allItem = library.GetItems(Q);
解决方案
您不需要<查询>
标记。这就是为什么没有被执行你的查询。
i'm trying to have some item from a sharepoint list, depends on date in a custom column.
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.
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. That's why you query isn't being executed.
这篇关于在CAML查询日期时间comparaison对于SharePoint的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文