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

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>
share|improve this question
    
Check this out: stackoverflow.com/questions/2573521/… ;) –  RJ Cuthbertson Feb 11 at 18:11

1 Answer 1

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

share|improve this answer
    
thanks , it works now –  Stan Feb 13 at 16:06
    
Happy to help :) Please accept the answer if it worked for you. –  RJ Cuthbertson Feb 13 at 16:33

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.