有没有人见过用于确定两个日期之间的合理区别的自定义代码示例。就像facebook上的一样。
发布于 2012-11-28 13:26:37
感谢您的帮助,在这个场景中,我认为这太复杂了,而且在SQL中很难很好地实现,这增加了这样一个事实,即当我打算使用jQuery更新这些值时,客户端逻辑会更高效。
找到了这个完全符合我目的的图书馆。
发布于 2012-11-28 10:02:23
虽然同意在表示层这样做可能更好,但这可以构成SQL解决方案的基础--如果您在Server上需要它,当然也可以用您选择的.Net语言编写一个CLR函数。
declare @d datetime = '2012-10-11 00:52'
select
case
when diff < 60 then convert(varchar(5), DATEDIFF(s, @d, getdate())) + ' seconds'
when diff < 3600 then convert(varchar(5), DATEDIFF(MI, @d, getdate())) + ' minutes'
when diff < 86400 then convert(varchar(5), DATEDIFF(hh, @d, getdate())) + ' hours'
when diff < 604800 then convert(varchar(5), DATEDIFF(D, @d, getdate())) + ' days'
when diff < 2419200 then convert(varchar(5), DATEDIFF(WEEK, @d, getdate())) + ' weeks'
else convert(varchar(5), DATEDIFF(MONTH, @d, getdate())) + ' months'
end
from
(select DATEDIFF(s, @d, getdate()) as diff) vhttps://stackoverflow.com/questions/13600808
复制相似问题