Round .NET DateTime milliseconds, so it can fit SQL Server milliseconds

前端 未结 4 1476
孤独总比滥情好
孤独总比滥情好 2020-12-03 10:59

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

4条回答
  •  失恋的感觉
    2020-12-03 11:26

    Here's what you want:

    using System.Data.SqlTypes; // from System.Data.dll
    
    public static DateTime RoundToSqlDateTime(DateTime date)
    {
      return new SqlDateTime(date).Value;
    }
    

提交回复
热议问题