Monday 1 November 2010

Using CAML and SPQuery to query using dates

Problem: Using SPQuery I can't filter using a datatime parameter.
Hypothesis: I can see my custom web part code is formatting the DateTime selection (SharePoint:DateTimeControl) differently in my custom code CAML than the CAML generated by U2U.
Resolution:
Use the Microsoft.SharePoint.Utilities.SPUtility.CreateISO8601DateTimeFromSystemDateTime() method to get your DateTime control value into the correct format.
SPUtility.CreateISO8601DateTimeFromSystemDateTime(DateTime.UtcNow)

More Info:
http://blogs.msdn.com/b/saurabhkv/archive/2008/05/05/spquery-with-boolean-and-datetime.aspx
http://snahta.blogspot.com/2009/07/spquery-few-important-things.html
http://www.aidangarnish.net/post/Using-SPQuery-and-CAML-to-filter-and-order.aspx

0 comments:

Post a Comment