2012-10-10 78 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); 
相關問題