,因爲沒有工作的解決方法, DATETIME
data type的
Date range [is] January 1, 1753, through December 31, 9999.
您必須使用new data type DATETIME2
:
SET ANSI_WARNINGS OFF; --Not recommended
SET ARITHABORT OFF; --Not recommended
DECLARE @stringDate nvarchar(50)
SET @stringDate = '0001-01-01T12:00:00'
SELECT
@stringDate AS StringDate,
CONVERT(datetime, @stringDate, 126) AS Converted_DATETIME,
CONVERT(datetime2, @stringDate, 126) AS Converted_DATETIME2_A,
CONVERT(datetime2(0), @stringDate, 126) AS Converted_DATETIME2_B
結果:
StringDate Converted_DATETIME Converted_DATETIME2_A Converted_DATETIME2_B
------------------- ------------------ ---------------------- ----------------------
0001-01-01T12:00:00 NULL 0001-01-01 12:00:00.00 0001-01-01 12:00:00
Arithmetic overflow occurred.
注意:您可以更改DATETIME2
數據類型的默認精度,如果您的日期/時間值不具有 「小數秒精度」:DATETIME2(0)
。
作品一種享受!謝謝 – NiceYellowEgg 2012-04-18 11:07:06
SQL Server 2008 **中的'DATE'或'DATETIME2'數據類型將**支持'01/01/0001'日期..... – 2012-04-18 11:24:35
@marc_s yes,'DateTime2'正如我在答案中提到的... – Magnus 2012-04-18 11:27:57