SQL Server函数返回最小日期(1753年1月1日) [英] SQL Server function to return minimum date (January 1, 1753)

查看:1307
本文介绍了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)

这篇关于SQL Server函数返回最小日期(1753年1月1日)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆