declare @s varchar(8),@e varchar(8)select @s='20110101',@e='20110306'select cast(cast(@e as datetime)-cast(@s as datetime) as int) 相差天数, datediff(d,@s,@e) 函数验算相差天数 函数验算 ----------- ----------- 64 64(1 row(s) affected)
DECLARE @begintime DATETIME SET @begintime='20110101'DECLARE @endtime DATETIME SET @endtime='20110306' SELECT ABS(CAST(@begintime AS INT)-CAST(@endtime AS int))/* 64 */
declare @s varchar(8),@e varchar(8)select @s='20110101',@e='20110306'select
cast(cast(@e as datetime)-cast(@s as datetime) as int) 相差天数,
datediff(d,@s,@e) 函数验算相差天数 函数验算
----------- -----------
64 64(1 row(s) affected)
DECLARE @begintime DATETIME
SET @begintime='20110101'DECLARE @endtime DATETIME
SET @endtime='20110306'
SELECT ABS(CAST(@begintime AS INT)-CAST(@endtime AS int))/*
64
*/