2

I've already created another thread regarding this , but i want to make it more tidy and give more information.

I have two columns "StartDate" and "EndDate" . When i add the values and click save using this commands i get the correct dates as inserted :

DateTime startDate = Convert.ToDateTime(properties.ItemEventProperties.AfterProperties["StartDate"]);
                DateTime endDate = Convert.ToDateTime(properties.ItemEventProperties.AfterProperties["EndDate"]);

When i later on try to get the item using caml query with this code , i get the date 1 day before :

List leaveRequest = clientContext.Web.Lists.GetByTitle("LeaveRequest");

                CamlQuery getApprovedLeaves = new CamlQuery();

                string statusApproved = "Approved";

                getApprovedLeaves.ViewXml =
                    @"<View>
                            <Query>
                                <Where>

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

                                </Where>
                           </Query>
                           </View>";

                ListItemCollection approvedLeaves = leaveRequest.GetItems(getApprovedLeaves);

                clientContext.Load(approvedLeaves);
                clientContext.ExecuteQuery();

This is strange issue. Please note that i 've changed the regional settings but my dev is stored on Azure , so i remotely connect to the VM and debug from there with Visual Studio.

Does anyone have any idea how to fix this?

2

I have managed to do it by converting the start and end date to localtime.

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.