I have a method that gets a date property from a source (either a DataRow
or a SqlDataReader
):
protected SqlDateTime GetSqlDateTimePropertyValue(string propertyName, object source)
{
var objValue = GetPropertyValue(propertyName, source);
var value = objValue == DBNull.Value ? null : (DateTime?)objValue;
var sqlValue = new SqlDateTime();
if (value.HasValue) sqlValue = value.Value;
return sqlValue;
}
but the conversion appears to be changing the date slightly so that my test always fails.
Does anyone know why this method would be converting wrongly?
At the end of the method, it looks like the conversion to SqlDateTime
does some rounding:
value.Value.Ticks: 634698391707468296
sqlValue.Value.Ticks: 634698391707470000