日期:2014-05-20  浏览次数:20958 次

SQL怎么让回复时间显示为:1小前,2小前,1天前,.......
数据表里的回复记录是具体的时间,但是显示时怎么让回复时间显示为:1小前,2小前,1天前,.......

sql   语句怎么写啊??

------解决方案--------------------
查datediff()


------解决方案--------------------
用case()then
------解决方案--------------------
declare @date datetime
set @date= '2007-1-12 '
select case
when datediff(hh, @date,getdate()) < 24 then str(datediff(hh, @date,getdate())) + '小时前 '
when datediff(hh, @date,getdate()) > = 24 then str(datediff(dd, @date,getdate())) + '天前 '
end

------解决方案--------------------
SqlStr = "select top 20 hid,htype,hname,husername,hnum,case when datediff( 'hh ',hhdate,DateTime.Now()) < 60 then str(datediff( 'nn ',hhdate,DateTime.Now()))+ '小时前 ' --> as hhdate <--end from quan_hua order by hhdate desc ";

移到end 后面