开始时间 20110101  结束时间 20110306
求两个时间相差的天数?不弄用系统函数(datediff,datepart,等时间函数) 

解决方案 »

  1.   


    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)
      

  2.   


    DECLARE @begintime DATETIME
    SET @begintime='20110101'DECLARE @endtime DATETIME
    SET @endtime='20110306'
    SELECT ABS(CAST(@begintime AS INT)-CAST(@endtime AS int))/*
    64
    */