I have two date fields. Start and End Date . If i choose 10/25/2017 , when i debug it shows the value 24/10/2017 .

After some debugging , when item is being saved i can see the correct values. Once the item is saved , and then i read it with caml query , i get a day before. My opinion , because the server is hosted on azure , maybe when the item is saved it takes consideration of the location ? But i have also changed the regional settings to the correct ones.

Has anyone noticed this ever before ?

This happens with any date I choose

This is the code i use , after i added the list item :

using (clientContext)
            if (clientContext != null)
                List leaveRequest = clientContext.Web.Lists.GetByTitle("LeaveRequest");

                CamlQuery getApprovedLeaves = new CamlQuery();

                string statusApproved = "Approved";

                getApprovedLeaves.ViewXml =

                                        <FieldRef Name='Status'/>
                                        <Value Type = 'Choice'>" + statusApproved + @"</Value>


                ListItemCollection approvedLeaves = leaveRequest.GetItems(getApprovedLeaves);


 //Here is where the condition takes place. The "StartDate" and "EndDate" fields take a date of 1 days less. Its kind is UTC
 if (currentDate.Date >= Convert.ToDateTime(approvedLeaveItem["StartDate"]).Date && currentDate.Date <= Convert.ToDateTime(approvedLeaveItem["EndDate"]).Date)
                            conflictInfo[0] = "YES";
                            conflictInfo[1] = Convert.ToString(approvedLeaveItem["Requester"]);

It correctly returns 1 item which is approved but instead of StartDate = 25/10/2017 it shows 24 October.

Please note that when i add the date it displays it in format 10/25/2017 but in debug it shows 24 October

  • Is this issue happen only in the Debug Mode? could you please post a piece of your code? also, try to check the Regional Settings in your site setting! – Mohamed El-Qassas MVP Oct 25 '17 at 9:19
  • @M.Qassas I ve include more information for my issue as requested – shak Oct 25 '17 at 9:32
  • Also i changed the regional settings but still it doesn't work . The field Start Date in my code , has the value 24 of October instead of 25 – shak Oct 25 '17 at 11:41
  • Actually, it's wired issue, could you please check the server date time setting if you are working on SharePoint On-prem?! – Mohamed El-Qassas MVP Oct 25 '17 at 12:05
  • @M.Qassas Actually it is SharePoint Online BUT my development environment is hosted on Azure VM . So Visual Studio is hosted on Azure VM and not on my pc. However the debugging takes place again on Azure. I have checked property "Kind" of StartDate and is set to UTC. Current Date is displayed correctly to 25 October. – shak Oct 25 '17 at 12:27

It seems that when you query in SharePoint it returns the results in UTC . So the solution was to transform the returned date fields to localtime . Here is the solution :

DateTime startDateUTC = Convert.ToDateTime(approvedLeaveItem["StartDate"]);

DateTime endDateUTC = Convert.ToDateTime(approvedLeaveItem["EndDate"]);

DateTime startDateLocal = Convert.ToDateTime(Convert.ToString(startDateUTC.ToLocalTime()));

DateTime endDateLocal = Convert.ToDateTime(Convert.ToString(endDateUTC.ToLocalTime()));

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.