MS SQL 中 smalldatetime 类型只能精确到分钟。
/*创建表*/
CREATE TABLE TT
(
id SMALLINT IDENTITY(1,1),
CreateDate1 SMALLDATETIME,
CreateDate2 DATETIME
)
/*插入时间数据*/
INSERT INTO dbo.TT
( CreateDate1, CreateDate2 )
VALUES ( '2011-01-07 01:27:57.123', -- CreateDate1 - smalldatetime
'2011-01-07 01:27:57.123' -- CreateDate2 - datetime
)
/*查看数据*/
SELECT * FROM dbo.TT
/*数据结果*/
1 2011-01-07 01:28:00 2011-01-07 01:27:57.123
--可见,'2011-01-07 01:27:57.123'保存为smalldatetime类型时,自动被转换成了 2011-01-07 01:28:00
/*比较时间*/
--注意,比较时,MSSQL把'2011-01-07 01:27:29' 转换成了 '2011-01-07 01:27:00'
SELECT * FROM dbo.TT
WHERE CreateDate1 <= '2011-01-07 01:27:29'
--返回0行数据。
--注意,比较时,MSSQL把'2011-01-07 01:27:29' 转换成了 '2011-01-07 01:28:00'
SELECT * FROM dbo.TT
WHERE CreateDate1 <= '2011-01-07 01:27:30'
--返回1行数据。
转载于:https://blog.51cto.com/liweibird/473634