首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

SQL如何让回复时间显示为:1小前,2小前,1天前,

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

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 后面

热点排行