12
我想从一个SharePoint列表中获取一些项目,取决于自定义列中的日期。CAML查询Sharepoint中的日期时间比较
我已经使用U2U Caml Builder创建了我的查询,这很有效,但是当我将它放入自己的代码中时,它始终返回给我列表中的所有项目。
这里是我的代码:
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);
非常感谢!最糟糕的是,我已经帮助这个f ***错误的同事hahahaha! – 2011-01-11 07:48:46