0

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);

2 Answers 2

1

You should just be able to use this instead of trying to create a date.

  <Leq>
     <FieldRef Name='MaxDate' />
     <Value Type='DateTime'>
        <Today Offset='30' />
     </Value>
  </Leq>
1
  • Still not working. I think it has something to do with MaxDate being a calculated field. I am testing against another calculated field, that simply returns '1' instead of a DateTime, to leave the DateTime element out.
    – CigarDoug
    Jun 11, 2013 at 10:12
0

BTW, you haven't closed the FieldRef tag.

2
  • please provide more details. Apr 1, 2014 at 13:53
  • Fixed. But this should be a comment, not an answer.
    – CigarDoug
    Apr 1, 2014 at 17:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.