Datetime comparison in CAML Query for Sharepoint
Asked Answered
S

1

12

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);
Snag answered 10/1, 2011 at 15:42 Comment(0)
S
11

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

Santa answered 10/1, 2011 at 15:45 Comment(1)
Thank you a lot !!! The worst, that i already help a collegue on this f*** error hahahaha !Snag

© 2022 - 2024 — McMap. All rights reserved.