I want to get all the items that are created or modified from the last 4 hours from a SharePoint Online list using CSOM. I am using the below CAML query but i am not getting the items
DateTime startdate = DateTime.Now.AddHours(-4);
DateTime enddate = DateTime.Now;
var finalquery = "<View><Query><Where><Or><And><Geq><FieldRef Name='Created' /><Value IncludeTimeValue='TRUE' Type='DateTime'>" + startdate.ToString("yyyy-MM-ddTHH:mm:ssZ") + "</Value></Geq><Leq><FieldRef Name='Created' /><Value IncludeTimeValue='TRUE' Type='DateTime'>" + enddate.ToString("yyyy-MM-ddTHH:mm:ssZ") + "</Value></Leq></And><And><Geq><FieldRef Name='Modified' /><Value IncludeTimeValue='TRUE' Type='DateTime'>" + startdate.ToString("yyyy-MM-ddTHH:mm:ssZ") + "</Value></Geq><Leq><FieldRef Name='Modified' /><Value IncludeTimeValue='TRUE' Type='DateTime'>" + enddate.ToString("yyyy-MM-ddTHH:mm:ssZ") + "</Value></Leq></And></Or></Where></Query></View>";
I am converting the dates to .ToString("yyyy-MM-ddTHH:mm:ssZ")
while passing to CAML query
And my CAML Query is as below while debugging .
<View><Query><Where><Or><And><Geq><FieldRef Name='Created' /><Value IncludeTimeValue='TRUE' Type='DateTime'>2018-05-01T11:12:56Z</Value></Geq><Leq><FieldRef Name='Created' /><Value IncludeTimeValue='TRUE' Type='DateTime'>2018-05-01T15:17:54Z</Value></Leq></And><And><Geq><FieldRef Name='Modified' /><Value IncludeTimeValue='TRUE' Type='DateTime'>2018-05-01T11:12:56Z</Value></Geq><Leq><FieldRef Name='Modified' /><Value IncludeTimeValue='TRUE' Type='DateTime'>2018-05-01T15:17:54Z</Value></Leq></And></Or></Where></Query></View>
But all the items are created and modified recently
Can any one help me on this please.