2011-01-10 58 views
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); 

回答

11

你不需要<Query>標籤。這就是爲什麼你的查詢沒有被執行。

+0

非常感謝!最糟糕的是,我已經幫助這個f ***錯誤的同事hahahaha! – 2011-01-11 07:48:46