SQL Server function to return minimum date (January 1, 1753)

前端 未结 8 637
生来不讨喜
生来不讨喜 2021-02-01 11:43

I am looking for a SQL Server function to return the minimum value for datetime, namely January 1, 1753. I\'d rather not hardcode that date value into my script.

Does an

相关标签:
8条回答
  • 2021-02-01 12:22

    As I can not comment on the accepted answer due to insufficeint reputation points my comment comes as a reply.

    using the select cast('1753-1-1' as datetime) is due to fail if run on a database with regional settings not accepting a datestring of YYYY-MM-DD format.

    Instead use the select cast(-53690 as datetime) or a Convert with specified datetime format.

    0 讨论(0)
  • 2021-02-01 12:22

    Enter the date as a native value 'yyyymmdd' to avoid regional issues:

    select cast('17530101' as datetime)
    

    Yes, it would be great if TSQL had MinDate() = '00010101', but no such luck.

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