比较时间
time1= '2007-01-05 23:01:54 '
time2= '2006-12-14 17:17:12 '
如何去只比较time1/time2中的时间部分?
------解决方案--------------------select convert(varchar(8),time1,108)
------解决方案--------------------declare @str datetime
declare @str2 datetime
set @str= '2007-01-05 23:01:54 '
set @str2= '2006-12-14 17:17:12 '
select datename(hour,@str-@str2)+ ': '+datename(minute,@str-@str2)+ ': '+datename(second,@str-@str2)
------解决方案-------------------- --如何去只比较time1/time2中的时间部分?
DECLARE @TIME1 SMALLDATETIME,@TIME2 SMALLDATETIME
SET @time1= '2007-01-05 23:01:54 '
SET @time2= '2006-12-14 17:17:12 '
--SELECT CONVERT(CHAR(8),@TIME1,108), CONVERT(CHAR(8),@TIME2,108)
IF CONVERT(CHAR(8),@TIME1,108) <> CONVERT(CHAR(8),@TIME2,108)
PRINT '不相等 '
ELSE
PRINT '相等 '
------解决方案--------------------DECLARE @TIME1 datetime,@TIME2 datetime
SET @time1= '2007-01-05 23:01:54 '
SET @time2= '2006-12-14 17:17:12 '
select datediff(ss, convert(char(10),@time1,108), convert(char(10),@time2,108))
------解决方案--------------------select datediff(ss, convert(char(10), '2007-01-05 23:01:54 ',108), convert(char(10), '2006-12-14 17:17:12 ',108))