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 anything like that exist? (For comparison, in C#, I could just do
Or would I have to write this myself?
I am using Microsoft SQL Server 2008 Express.
You could write a User Defined Function that returns the min date value like this:
select cast(-53690 as datetime)
Then use that function in your scripts, and if you ever need to change it, there is only one place to do that.
Alternately, you could use this query if you prefer it for better readability:
select cast('1753-1-1' as datetime)
create function dbo.DateTimeMinValue() returns datetime as begin return (select cast(-53690 as datetime)) end
select dbo.DateTimeMinValue() as DateTimeMinValue DateTimeMinValue ----------------------- 1753-01-01 00:00:00.000
Answered By – D'Arcy Rittich
Answer Checked By – Marie Seifert (BugsFixing Admin)