DateTime2 vs DateTime in SQL Server

前端 未结 14 1068
谎友^
谎友^ 2020-11-22 06:04

Which one:

  • datetime
  • datetime2

is the recommended way to store date and time in SQL Server 2008+?

I\'m aware of differ

14条回答
  •  名媛妹妹
    2020-11-22 06:30

    Select ValidUntil + 1
    from Documents
    

    The above SQL won't work with a DateTime2 field. It returns and error "Operand type clash: datetime2 is incompatible with int"

    Adding 1 to get the next day is something developers have been doing with dates for years. Now Microsoft have a super new datetime2 field that cannot handle this simple functionality.

    "Let's use this new type that is worse than the old one", I don't think so!

提交回复
热议问题