In WSS 3.0, I have a list with a Calculated Field, 'MaxDate'. It gets the greater of two other dates, Notional Date and Override Date.
I am trying (and failing) to build a CAML query to get all items in the list where MaxDate is within 30 days of today. No matter what parameters I change, I never get any results. I have tried ValueType as DateTime and Calculated; set IncludeValueTime to True, False, and omitted altogether; tried static strings of strMaxDate; tried Geq, Leq, and Eq with values one day above, below, and equal to today, and never get even one result. No errors, just no results.
Here is my current code:
// Get Now + 30, with Time set to zero // SPUtility is used to convert to ISO8601 standard for CAML dates DateTime dtmNow = DateTime.Now.AddDays(30); dtmNow = new DateTime(dtmNow.Year, dtmNow.Month, dtmNow.Day); string strMaxDate = SPUtility.CreateISO8601DateTimeFromSystemDateTime(dtmNow); // Build Query SPQuery objQuery = new SPQuery(); objQuery = string.Concat( "<Where>", "<Leq>", "<FieldRef Name='MaxDate'>", "<Value Type='DateTime' IncludeTimeValue='False'>", strMaxDate, "</Value>", "</Leq>", "</Where>"); // Populate collection (always zero items) SPListItemCollection objListItems = objList.GetItems(objQuery);