SQL计算两个时间段的差,精确到秒(可用于倒计时)

declare @day int
declare @hour int
declare @min int
declare @sec int
declare @alls int
set @alls=datediff(s,'2015-05-01 23:23:59',GETDATE())   --时间1与时间2之间的差
set @day=@alls/86400
set @hour=(@alls-@day*86400)/3600
set @min=(@alls-@day*86400-@hour*3600)/60
set @sec=@alls-@day*86400-@hour*3600-@min*60
select CAST(@day as varchar(5))+'天'+CAST(@hour as varchar(2))+'小时'+CAST(@min as varchar(2))+'分'+CAST(@sec as varchar(2))+'秒' cha

你可能感兴趣的:(SQL)