0

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.

1

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)

2
  • Thanks a lot for this! You missed a backslash in the last line </View>. Jan 7 at 4:31
  • Glad to hear it helped you, and thanks for your feedback Jan 7 at 4:46

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.