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

前端 未结 8 642
生来不讨喜
生来不讨喜 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:05

    This is what I use to get the minimum date in SQL Server. Please note that it is globalisation friendly:

    CREATE FUNCTION [dbo].[DateTimeMinValue]()
    RETURNS datetime
    AS
    BEGIN
      RETURN (SELECT
        CAST('17530101' AS datetime))
    END
    

    Call using:

    SELECT [dbo].[DateTimeMinValue]()
    

提交回复
热议问题