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

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


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)

Example Function

create function dbo.DateTimeMinValue()returns datetime asbegin    return (select cast(-53690 as datetime))end

Usage

select dbo.DateTimeMinValue() as DateTimeMinValueDateTimeMinValue-----------------------1753-01-01 00:00:00.000


Have you seen the SqlDateTime object? use SqlDateTime.MinValue to get your minimum date (Jan 1 1753).


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.