Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Datetime comparison in CAML Query for Sharepoint

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);
like image 761
Garcia Julien Avatar asked Jan 10 '11 15:01

Garcia Julien


1 Answers

You don't need the <Query> tag. That's why you query isn't being executed.

like image 99
Tundey Avatar answered Oct 20 '22 15:10

Tundey