Datetime comparaison in CAML Query for Sharepoint
Posted
by
Garcia Julien
on Stack Overflow
See other posts from Stack Overflow
or by Garcia Julien
Published on 2011-01-10T15:42:41Z
Indexed on
2011/01/10
15:54 UTC
Read the original article
Hit count: 249
Hi, i'm trying to have some item from a sharepoint list, depends on date in a custom column.
I've created my query with 2U2 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);
© Stack Overflow or respective owner