常用的日期段查询语句如下:1. 今天:WHERE date_column = CONVERT(date, GETDATE())2. 昨天:WHERE date_column = CONVERT(date, DATEADD(day, -1, GETDATE()))3. 明天:WHERE date_column = CONVERT(date, DATEADD(day, 1, GETDATE()))4. 本月:WHERE YEAR(date_column) = YEAR(GETDATE()) AND MONTH(date_column) = MONTH(GETDATE())5. 上个月:WHERE YEAR(date_column) = YEAR(DATEADD(month, -1, GETDATE())) AND MONTH(date_column) = MONTH(DATEADD(month, -1, GETDATE()))6. 上半年:WHERE YEAR(date_column) = YEAR(GETDATE()) AND MONTH(date_column) <= 67. 下半年:WHERE YEAR(date_column) = YEAR(GETDATE()) AND MONTH(date_column) > 68. 去年:WHERE YEAR(date_column) = YEAR(DATEADD(year, -1, GETDATE()))9. 前三年:WHERE YEAR(date_column) BETWEEN YEAR(DATEADD(year, -3, GETDATE())) AND YEAR(DATEADD(year, -1, GETDATE()))10. 本周第一天:WHERE date_column >= CONVERT(date, DATEADD(wk, DATEDIFF(wk, 0, GETDATE()), 0))11. 本月第一天:WHERE date_column >= CONVERT(date, DATEADD(mm, DATEDIFF(mm, 0, GETDATE()), 0))12. 本月最后一天:WHERE date_column < CONVERT(date, DATEADD(mm, DATEDIFF(mm, 0, GETDATE()) + 1, 0))13. 某月第一天:WHERE date_column >= CONVERT(date, '2022-01-01', 0)14. 某月最后一天:WHERE date_column < DATEADD(month, 1, CONVERT(date, '2022-01-01', 0)))15. 本年第一天:WHERE date_column >= CONVERT(date, YEAR(GETDATE())+'-01-01', 0)16. 本年最后一天:WHERE date_column < CONVERT(date, YEAR(GETDATE())+'-01-01', 0)17. 某一天和今天相隔多少天:SELECT DATEDIFF(day, '2022-01-01', GETDATE())18. 7天内:WHERE date_column >= DATEADD(day, -7, GETDATE())19. 15天内:WHERE date_column >= DATEADD(day, -15, GETDATE())20. 1个月内:WHERE date_column >= DATEADD(month, -1, GETDATE())21. 3个月内:WHERE date_column >= DATEADD(month, -3, GETDATE())22. 1年内:WHERE date_column >= DATEADD(year, -1, GETDATE())23. 3年内:WHERE date_column >= DATEADD(year, -3, GETDATE())其中,date_column为日期列名,可以根据实际情况进行替换。
联系客服