Weird bug,
When inserting a SharePoint list item I set the date submitted to DateTime.Now and it is working fine as when I check SharePoint I see the item inserted just fine with the correct date and all values.
oListItem["Date_x0020_Submitted"] = DateTime.Now;
But when I go to retrieve the exact same list item for some reason the date comes back as 4 hours into the future!!
query.ViewXml = "<View><Query><OrderBy><FieldRef Name='Date_x0020_Submitted' Ascending='FALSE' /></OrderBy></Query><RowLimit>1</RowLimit></View>";
SP.ListItemCollection issuesCollection = oList.GetItems(query);
MyContext.Load(issuesCollection, (items => items.Include(item => item["ID"], item => item["Date_x0020_Submitted"])));
Just to reiterate, after inserting the item I can see it in the list with the correct exact date inserted, but when I retrieve it for some reason it is 4 hours into the future. For example in SharePoint it shows me 10:53, but when I retrieve it shows 2:53.
Does anyone know why this might be happening? It happens for every single item that I insert and retrieve.
The time which you store is your local time (UTC-5:00, probably with DST).
Is there any chance that the time returned by Sharepoint is returned as UTC time?
Kindproperty ofDateTimeclass tells what kind of time it is (this has changed through different versions of .NET framework):You can convert the returned time to local time and see if it matches:
As you say that your time is given as a string (although I suspect that as that format doesn’t look like string), you can try to parse it: