2

I would like to filter a list based on the year as parameter. For e.x. if i use 2014, all items from 1/1/2014 to 31/12/2014 should appear and also i am filtering on region. For the caml query below, if there is an item which was entered on 1/1/2014, it does not show up.Any idea why...

<Query>
  <Where>
  <And>
     <Eq>
        <FieldRef Name='Region' />
        <Value Type='Lookup'>A1.1</Value>
     </Eq>
     <And>
        <Geq>
           <FieldRef Name='DueDate' />
           <Value IncludeTimeValue='FALSE' Type='DateTime'>2014-01-01</Value>
        </Geq>
        <Leq>
           <FieldRef Name='DueDate' />
           <Value IncludeTimeValue='FALSE' Type='DateTime'>2014-12-31</Value>
        </Leq>
     </And>
  </And>
</Where>
<OrderBy>
  <FieldRef Name='DueDate' Ascending='False' />
 </OrderBy>
</Query>
4

You need to use the ISO 8601 DateTime format:

yyyy-MM-ddTHH:mm:ssZ

Even if you aren't comparing against the time value, the ISO 8601 format is still expected.

Given DateTime dueDate You can use:

<Value IncludeTimeValue='FALSE' Type='DateTime'>dueDate.ToString("yyyy-MM-ddTHH:mm:ssZ")</Value>

Or the SPUtility.CreateISO8601DateTimeFromSystemDateTime() method:

<Value IncludeTimeValue='FALSE' Type='DateTime'>SPUtility.CreateISO8601DateTimeFromSystemDateTime(dueDate)</Value>

See SharePoint 2010 Working with Dates in CAML

  • Like this solutions but how can i offset the dates using any of these methods? – naijacoder Dec 18 '14 at 5:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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