Query data in a date range

1. All data query today

select * from table where datediff (day, field names, getdate ()) = 0

2. All queries yesterday's data

select * from table where datediff (day, field names, getdate () - 1) = 0

3. today's date data in a query anniversary

selcet * from table where datediff (week, field names, getdate () - 1) = 0

4. 30 days before the query data

select * from table where datediff (d, field names, getdate ()) <= 30

5. the query data on the month

select * from table where datediff (m, field names, getdate ()) <= 1

data query day 6. the

select * from table where datediff (dd, field names, getdate ()) = 0

7. the query data within 24 hours of

select * from table where datediff (hh, field names, getdate ())

8. the data query week

select * from table where datediff (week, field names, getdate ()) = 0

9. the data query month

select * from table where datediff (month, field names, getdate ()) = 0

10. the query data season

select * from table where datediff (qq, field names, getdate
()) = 0 ----------------
Disclaimer: This article is CSDN blogger original article "smartsmile2012", and follow CC 4.0 BY-SA copyright agreement, reproduced, please attach the original source link and this statement.
Original link: https: //blog.csdn.net/smartsmile2012/article/details/93976959

Guess you like

Origin www.cnblogs.com/Anthony518/p/11456755.html