I have a method that gets the date property from the source (either DataRow or 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 seems to change the date a bit, so my test always fails.
Does anyone know why this method will not be converted correctly?
At the end of the method, it looks like the conversion to SqlDateTime does some rounding:
value.Value.Ticks: 634698391707468296 sqlValue.Value.Ticks: 634698391707470000
Ev.
source share