Sharepoint - Using Date offset in CAML query

You'd use something like this, using the BIWUG CamlDesigner:

       <Where>
      <Or>
         <Geq>
            <FieldRef Name='StartDate' />
            <Value Type='DateTime'>
               <Today OffsetDays='30' />
            </Value>
         </Geq>
         <Leq>
            <FieldRef Name='StartDate' />
            <Value Type='DateTime'>
               <Today OffsetDays='-60' />
            </Value>
         </Leq>
      </Or>
   </Where>

Update for SharePoint 2013: although MSDN lists Offset as an attribute for Today element (https://msdn.microsoft.com/en-us/library/office/ms460496.aspx), when customizing the CAML on a list view in SharePoint Designer 2013 I tried the Offset attribute but it didn't work. I used the "OffsetDays" attribute (not documented in MSDN) and the query returned the desired output (items with date field up to 5 days from the current date).


Marked answer won't work (at least in SP 2010) unless you change the Today Offset bit to "Today OffsetDays" thus having:

<Where>
  <And>
     <Geq>
        <FieldRef Name='EventDate' />
        <Value Type='DateTime'>
           <Today OffsetDays='-30' />
        </Value>
     </Geq>
     <Leq>
        <FieldRef Name='EventDate' />
        <Value Type='DateTime'>
           <Today OffsetDays='60' />
        </Value>
     </Leq>
  </And>

Cheers!

Tags: