Reading a DateTime value from a SharePoint list
When working with list data in SharePoint code, what's the difference between these two calls?
// read method 1
string sDateTimeValue = listRow["SampleDateTime"].ToString();
// -------------------------------------------
// read method 2
DateTime dDateTimeValue = new DateTime();
DateTime.TryParse(listRow.GetFormattedValue("SampleDateTime"), out dDateTimeValue );
Well, in my experience, the difference is about 5 hours.
Yup - if, at 4:50pm, you put DateTime.Now into listRow["SampleDateTime"] then try to read it out using the two lines above, the value of sDateTimeValue will be 4:50pm and the value of dDateTimeValue will be 11:50am. I'm deliberately leaving off the date portion - don't e-mail me about that.
Before you ask, yes - my web application's time zone had been set correctly to the Eastern time zone and the individual user was set to follow the web application.
I have no idea why this happened, but I thought I should document that it did happen.