0

I'm trying to get a CAML query working with dates - specifically PublishingStartDate and PublishingExpirationDate.

When scheduling an item, there is the option to select 'immediately' and 'never' for the start and end dates. My understanding of these options is that they create a null value instead of a date so I need to query for 'null or later than the start date' and also 'null or before the end date' if that makes sense.

I'm trying to use this in a query builder without much luck so any guidance in the right direction would be appreciated.

<Query>
<Where>
  <And>
     <And>
        <Or>
           <IsNull>
              <FieldRef Name='PublishingStartDate' />
           </IsNull>
        </Or>
        <Leq>
           <FieldRef Name='PublishingStartDate' />
           <Value Type='DateTime'>
              <Today OffsetDays='0' />
           </Value>
        </Leq>
     </And>
     <And>
        <Or>
           <IsNull>
              <FieldRef Name='PublishingExpirationDate' />
           </IsNull>
        </Or>
        <Geq>
           <FieldRef Name='PublishingExpirationDate' />
           <Value Type='DateTime'>
              <Today OffsetDays='0' />
           </Value>
        </Geq>
     </Or>
  </And>
</Where>
</Query>
1

Your OR and AND tags are not correct. They should wrap the two items being operated:

<Query>
  <Where>
       <And>
         <Or>
           <IsNull>
             <FieldRef Name='PublishingStartDate' />
           </IsNull>
           <Leq>
             <FieldRef Name='PublishingStartDate' />
             <Value Type='DateTime'>
               <Today OffsetDays='0' />
             </Value>
           </Leq>
         </Or>           
         <Or>
          <IsNull>
            <FieldRef Name='PublishingExpirationDate' />
          </IsNull>   
          <Geq>
            <FieldRef Name='PublishingExpirationDate' />
            <Value Type='DateTime'>
              <Today OffsetDays='0' />
            </Value>
         </Geq>
        </Or>
     </And>
  </Where>
</Query>
  • Thanks - I ended up just creating a new StartDate/EndDate column instead of using the OOTB scheduling feature which turned out to be incredibly easier than doing a QueryOverride. – Aaron Feb 10 '15 at 17:00

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.