Transact-SQL 参考

datetime 和 smalldatetime

代表日期和一天内的时间的日期和时间数据类型。

datetime

从 1753 年 1 月 1 日到 9999 年 12 月 31 日的日期和时间数据,精确度为百分之三秒(等于 3.33 毫秒或 0.00333 秒)。如下表所示,把值调整到 .000、.003、或 .007 秒的增量。

示例 调整后的示例
01/01/98 23:59:59.999 1998-01-02 00:00:00.000
01/01/98 23:59:59.995,
01/01/98 23:59:59.996,
01/01/98 23:59:59.997, 或
01/01/98 23:59:59.998
1998-01-01 23:59:59.997
01/01/98 23:59:59.992,
01/01/98 23:59:59.993,
01/01/98 23:59:59.994
1998-01-01 23:59:59.993
01/01/98 23:59:59.990 或
01/01/98 23:59:59.991
1998-01-01 23:59:59.990

Microsoft® SQL Server™ 拒绝所有其不能识别为 1753 年到 9999 年间的日期的值。

smalldatetime

从 1900 年 1 月 1 日到 2079 年 6 月 6 日的日期和时间数据精确到分钟。29.998 秒或更低的 smalldatetime 值向下舍入为最接近的分钟,29.999 秒或更高的 smalldatetime 值向上舍入为最接近的分钟。

--returns time as 12:35
SELECT CAST('2000-05-08 12:35:29.998' AS smalldatetime)
GO
--returns time as 12:36
SELECT CAST('2000-05-08 12:35:29.999' AS smalldatetime)
GO
注释

Microsoft SQL Server 用两个 4 字节的整数内部存储 datetime 数据类型的值。第一个 4 字节存储 base date(即 1900 年 1 月 1 日)之前或之后的天数。基础日期是系统参考日期。不允许早于 1753 年 1 月 1 日的 datetime 值。另外一个 4 字节存储以午夜后毫秒数所代表的每天的时间。

smalldatetime 数据类型存储日期和每天的时间,但精确度低于 datetime。SQL Server 将 smalldatetime 的值存储为两个 2 字节的整数。第一个 2 字节存储 1900 年 1 月 1 日后的天数。另外一个 2 字节存储午夜后的分钟数。日期范围从1900 年 1 月 1 日到 2079 年 6 月 6 日,精确到分钟。

请参见

ALTER TABLE

CAST 和 CONVERT

CREATE TABLE

数据类型转换

数据类型

DECLARE @local_variable

DELETE

INSERT

SET @local_variable

UPDATE