Omitting the Milliseconds in a Date

后端 未结 7 558
梦如初夏
梦如初夏 2020-12-09 15:16

When I select from SQL Server, I want to get a date, but omit the millisecond value, and I want it to be as a date type. So if I have a value 1/1/2009 1:23:11.923

相关标签:
7条回答
  • 2020-12-09 16:20
    DATEADD(SECOND, DATEDIFF(SECOND, 0, < your datetime column >), 0)
    

    May need to change the 0 to something else to prevent an overflow error. Don't have a SQL Server at hand right now to verify.

    While this method does not appear to be intuitive at first sight, have a look here for the rationale behind it: http://karaszi.com/the-ultimate-guide-to-the-datetime-datatypes

    0 讨论(0)
提交回复
热议问题