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

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/cplvfx/article/details/82023423


===查询某天所有数据===
方法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

猜你喜欢

转载自blog.csdn.net/cplvfx/article/details/82023423