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 have a list with a datetime filed.

I want selected items from this with date rang.

I use this code

<Where>  
 <And>
  <Geq>
    <FieldRef Name='SendDate' /> <Value IncludeTimeValue='TRUE' Type='DateTime'>8/3/2012 12:00:00 AM</Value>
  </Geq>
  <Leq>
    <FieldRef Name='SendDate' />
    <Value IncludeTimeValue='TRUE' Type='DateTime'>8/5/2012 12:00:00 AM</Value> 
  </Leq>
 </And>
</Where>

I have item in this range but don't show any item in quary.

share|improve this question

2 Answers 2

up vote 1 down vote accepted

What is important here is to get the datetime format right. If you use it programatically you could either use this

string sendDate = sendDate.ToString("yyyy-MM-ddTHH:mm:ssZ");

..or you could use the SPUtility.CreateISO8601DateTimeFromSystemDateTime method to achieve the same. Beyond this you could also consider using "relative" expressions based on Today such in (translated into "30 days ago")

 <Geq>
        <FieldRef Name="SendDate" />
<Value Type='DateTime'>
               <Today OffsetDays='-30' />
            </Value>
      </Geq>
share|improve this answer
    
Thanks a lot :) –  ar.gorgin Aug 5 '12 at 4:00

Create your query with the U2U Caml Query builder:

http://www.u2u.be/Tools/wincamlquerybuilder/CamlQueryBuilder.aspx

(This works with 2010 as well)

Ideally the following query should work:

<Query>
  <Where>
    <And>
      <Geq>
        <FieldRef Name="SendDate" />
          <Value IncludeTimeValue="TRUE" Type="DateTime">2011-01-01T15:55:52Z</Value>
      </Geq>
      <Leq>
        <FieldRef Name="SendDate" />
        <Value IncludeTimeValue="TRUE" Type="DateTime">2011-12-31T15:56:29Z</Value>
      </Leq>
    </And>
  </Where>
</Query>
share|improve this answer

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.