2012-10-10 44 views
1

在SharePoint 2010中,我需要根据条件从列表中获取项目。考虑其中一个字段为DateTime类型的日期,条件是:CAML过滤器从列表中获取当前月份?

获取当前月份数据。

如何使用CAML查询根据此条件过滤列表项目?

通过, 的Raji

回答

3

使用SPUtility.CreateISO8601DateTimeFromSystemDateTime创建相关的时间字符串

DateTime firstDay = new DateTime(DateTime.Now.Year, DateTime.Now.Month, 1); 
Sting stringQuery = 
String.Format(@"<And> 
        <Geq> 
        <FieldRef Name='Date' /> 
        <Value Type='DateTime'>{0}</Value> 
       </Geq> 
       <Leq> 
        <FieldRef Name='Date' /> 
        <Value Type='DateTime'>{1}</Value> 
       </Leq> 
       </And>", 
       SPUtility.CreateISO8601DateTimeFromSystemDateTime(firstDay), 
       SPUtility.CreateISO8601DateTimeFromSystemDateTime(firstDay .AddMonths(1))); 
SPQuery query = new SPQuery(stringQuery); 
相关问题