Question

I am trying to write a Caml Query to get only today's list items and then later copy it into the new list.

I am using the batch method to copy data from source list to destination.

source list gets updated daily with new list items.

Current Caml query which still gets all the data and not today's:

$Query = New-Object Microsoft.SharePoint.Client.CamlQuery
$Query.ViewXml = @"
    <View Scope='RecursiveAll'>
        <Query>
           <Eq> 
            <FieldRef Name='Date' Ascending='TRUE'/>
            <Value IncludeTimeValue='False' Type='DateTime'><Today /></Value> # Did not work on true
           </Eq>
        </Query>
        <RowLimit Paged="TRUE">5</RowLimit>
    </View>
"@

I tried IncludeTimeValue='False' as well as IncludeTimeValue='True' both are giving the same results.

What should be my Caml query to get only today's list items?

Ask me questions for more details if needed.

Was it helpful?

Solution

The <Where> clause is missing in your Query! Also, make sure that the data type of the field Date is DateTime.

<View>
 <Query>
  <Where>
    <Eq>
    <FieldRef Name='Date'/>
    <Value Type='DateTime'><Today /></Value>
    </Eq>
  </Where>
 </Query>
</View>

You can also use IncludeTimeValue='TRUE' with <Geq> (Greater than or equal)

Licensed under: CC-BY-SA with attribution
Not affiliated with sharepoint.stackexchange
scroll top