1

How to filter items between two dates with camel query?

For example, I want to retrieve items created between 2019-9-1 and 2019-10-5.

1

Date and time in sharepoint is ISO 8601 format. You could try the below script:

$spweb = get-spweb http://sp/sites/test/ 
$splist = $spweb.Lists.TryGetList("TestList")
$query = New-Object Microsoft.SharePoint.SPQuery
$query.Query = 
   "   <Where>
      <And>
         <Geq>
            <FieldRef Name='Created' />
            <Value Type='DateTime'>2019-09-01T12:00:00Z</Value>
         </Geq>
         <Leq>
            <FieldRef Name='Created' />
            <Value Type='DateTime'>2019-10-05T12:00:00Z</Value>
         </Leq>
      </And>
   </Where>"; 
$items = $splist.GetItems($query)
| improve this answer | |
1

Try using something like below:

<Query>
  <Where>
    <And>
      <Geq>
        <FieldRef Name="Created" />
        <Value IncludeTimeValue="FALSE" Type="DateTime">2019-09-01</Value>
      </Geq>
      <Leq>
        <FieldRef Name="Created" />
        <Value IncludeTimeValue="FALSE" Type="DateTime">2019-10-5</Value>
      </Leq>
    </And>
  </Where>
</Query>
| improve this answer | |

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.