I am saving a DateTime value in one of the field in SharePoint list :
//request is an entity that has all he fields in the list, I am only showing DueDate in the below code
if (txtdatepicker.Text != String.Empty)
{
DateTime dueDate;
if (DateTime.TryParse(txtdatepicker.Text, out dueDate))
{
request.DueDate = dueDate;//Output {9/30/2017 12:00:00 AM}
}
}
The Date is correctly saved in SharePoint list as Due Date: 9/30/2017
.
Now the issue is when i try to retrieve this Date value :
if (LI[Constants.FieldName_ReqLst_DueDate] != null)
req.DueDate = (DateTime)LI[Constants.FieldName_ReqLst_DueDate];//Output {9/29/2017 6:30:00 PM}
The output i get here is totally different from that of the value that is saved. How to fetch the correct Date value from a SharPoint DateTime column?
DateTime.Parse(Convert.ToString(LI[Constants.FieldName_ReqLst_DueDate])).ToLocalTime()
it works fine but is it the correct way to do it? – Ishan Sep 28 '17 at 8:15