0
点赞
收藏
分享

微信扫一扫

asp.net, c#,时间查询大全, sql语句 用于SQLServer(mssql)

皮皮球场 2022-06-17 阅读 71

===查询某天所有数据===
方法1

select * from [article]
where Convert(varchar(10),[add_time],111) = '2017/04/22'

方法2

select * from [article]
where Convert(varchar(10),[add_time],120) = '2017-04-22'

===查询大于某一时间的数据===

select * from article
where add_time >= '2017-04-12 00:00:00'

===区间查询===
方法1

select * from [article]
where [add_time] between '2017-04-01 00:00:00' and '2017-04-20 00:00:00'

方法2

select * from [article]
where [add_time] >= '2017-04-10 00:00:00' and [add_time] <= '2017-04-20 00:00:00'

===查询10天前的当天所有数据,精确到天===

select * from [article]
where datediff(dd,[add_time],getdate()) = 10

===查询今天的当天所有数据===

select * from [article]
where datediff(dd,[add_time],getdate()) = 0

 


举报

相关推荐

0 条评论