SQL Server函数返回最小日期(1753年1月1日)

SQL Server函数返回最小日期(1753年1月1日)

问题描述:

我正在寻找SQL Server函数来返回日期时间的最小值,即1753年1月1日。我宁愿不将该日期值硬编码到我的脚本中。

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.

有什么样的存在吗? (为了比较,在C#中,我可以做 DateTime.MinValue)
或者我必须自己写这个?

Does anything like that exist? (For comparison, in C#, I could just do DateTime.MinValue) Or would I have to write this myself?

我正在使用Microsoft SQL Server 2008 Express。

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)