SQL怎么让回复时间显示为:1小前,2小前,1天前,.......

xm0592 2007-01-12 02:08:51
数据表里的回复记录是具体的时间,但是显示时怎么让回复时间显示为:1小前,2小前,1天前,.......

sql 语句怎么写啊??
...全文
167 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
xm0592 2007-01-12
  • 打赏
  • 举报
回复
SqlStr = "select top 20 hid,htype,hname,husername,hnum,case when datediff('hh',hhdate,DateTime.Now()) < 60 then str(datediff('nn',hhdate,DateTime.Now()))+'小时前' end as hhdate from quan_hua order by hhdate desc";

这样吗,和开始的错误是一样的,
错误提示是:
错误原因:为 datediff 指定了无效的参数 1。
coowoo 2007-01-12
  • 打赏
  • 举报
回复
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 后面
xm0592 2007-01-12
  • 打赏
  • 举报
回复
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";

偶这样写还是出错啊
coowoo 2007-01-12
  • 打赏
  • 举报
回复
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
xm0592 2007-01-12
  • 打赏
  • 举报
回复
case (datediff('h',hhdate,DateTime.Now()) <1) then datediff('n',hhdate,DateTime.Now())+'分钟前' as hhdate

这样写出错,偶还是不知道要怎么写,哪位高手可以帮写一个吗
honkerhero 2007-01-12
  • 打赏
  • 举报
回复
用case()then
xm0592 2007-01-12
  • 打赏
  • 举报
回复
有没有知道要怎么写的啊???
ld_thinking 2007-01-12
  • 打赏
  • 举报
回复
查datediff()

110,538

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧