Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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);
share|improve this question
add comment

2 Answers 2

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>
share|improve this answer
    
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 '13 at 10:12
add comment

BTW, you haven't closed the FieldRef tag.

share|improve this answer
    
please provide more details. –  Karthik Jaganathan Apr 1 at 13:53
    
Fixed. But this should be a comment, not an answer. –  CigarDoug Apr 1 at 17:39
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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