您的位置:首页 > 数据库

数据表中有字段time(类型为varchar),如何通过sql语句找出这个字段里力离当前最近的一个日期

2010-11-20 14:21 1006 查看
create table tb(time datetime)
insert into tb select '2010-10-25 22:10:30' union all select '2010-11-03 15:20:00' union all select '2010-12-15 11:11:11'
go
select * from tb a where abs(datediff(s,getdate(),time))=(select min(abs(datediff(s,getdate(),time))) from tb)
go
drop table tb
/*
time
-----------------------
2010-11-03 15:20:00.000

(1 行受影响)
*/
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐