I want to convert the datetime value to the value that I will get from SQL Server 2008.
SQL Server truncate the milliseconds to 3 digits, so I truncate the milliseco
Recommend building upon @RobSiklos solution since use of SqlDateTime in this fashion results in the loss of timezone information that the 'date' argument provided. Find its best practice to ensure timezone info is consistent at the point of conversion by adding a call to DateTime.SpecifyKind:
using System.Data.SqlTypes; // from System.Data.dll
public static DateTime RoundToSqlDateTime(DateTime date)
{
return DateTime.SpecifyKind( new SqlDateTime(date).Value, date.Kind);
}