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 milliseconds already. But the problem is that as you can see here: Milliseconds wrong when converting from XML to SQL Server datetime. SQL Server also has an precision issue.
Millisecond / microsecond precision optional since version 5.3 . SQLite: Datetimes can be stored as strings with arbitrary precision, but "only the first three digits are significant". Oracle: Default 1 microsecond. Optional precision to 1 nanosecond.
We can use DATEPART() function to get the MILLISECOND part of the DateTime in Sql Server, here we need to specify datepart parameter of the DATEPART function as millisecond or mi .
Here's what you want:
using System.Data.SqlTypes; // from System.Data.dll
public static DateTime RoundToSqlDateTime(DateTime date)
{
return new SqlDateTime(date).Value;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With