T-SQL日期处理总结(3)
来源:未知 责任编辑:责任编辑 发表时间:2013-12-18 11:36 点击:次
5: SELECT CONVERT(datetime,CONVERT(char(8),DATEADD(Month,DATEPART(Quarter,GETDATE())*3-Month(GETDATE())-2,GETDATE()),120)+'1') AS FDATE
6: ,CONVERT(datetime,CONVERT(char(8),DATEADD(Month,DATEPART(Quarter,GETDATE())*3-Month(GETDATE()),GETDATE()),120)
7: +CASE WHEN DATEPART(Quarter,GETDATE()) in(1,4)
8: THEN '31'ELSE '30' END) AS LDATE
9:
10:
11: SELECT CONVERT(datetime,CONVERT(char(8),DATEADD(Month,DATEPART(Quarter,GETDATE())*3-Month(GETDATE())-2,GETDATE()),120)+'1') AS FDATE
12: ,DATEADD(Day,-1,CONVERT(char(8),DATEADD(Month,1+DATEPART(Quarter,GETDATE())*3-Month(GETDATE()),GETDATE()),120)+'1') AS LDATE
13:
14: --给定日期所在月份的第一天和最后一天
15: SELECT CONVERT(datetime,CONVERT(char(8),GETDATE(),120)+'1') AS FDATE,DATEADD(Day,-1,CONVERT(char(8),DATEADD(Month,1,GETDATE()),120)+'1') AS LDATE www.2cto.com
16:
17: --给定日期所在周的取星期几的日期,星期天做为一周的第1天
18: SELECT DATEADD(Day,0-(DATEPART(Weekday,GETDATE())+@@DATEFIRST-1)%7,GETDATE())
19: SELECT DATEADD(Day,1-(DATEPART(Weekday,GETDATE())+@@DATEFIRST-1)%7,GETDATE())
20: SELECT DATEADD(Day,2-(DATEPART(Weekday,GETDATE())+@@DATEFIRST-1)%7,GETDATE())
21: SELECT DATEADD(Day,3-(DATEPART(Weekday,GETDATE())+@@DATEFIRST-1)%7,GETDATE())
22: SELECT DATEADD(Day,4-(DATEPART(Weekday,GETDATE())+@@DATEFIRST-1)%7,GETDATE())
23: SELECT DATEADD(Day,5-(DATEPART(Weekday,GETDATE())+@@DATEFIRST-1)%7,GETDATE())
24: SELECT DATEADD(Day,6-(DATEPART(Weekday,GETDATE())+@@DATEFIRST-1)%7,GETDATE())
25:
26: --昨天
27: SELECT DATEADD(Day,-1,GETDATE())
28: --前天
29: SELECT DATEADD(Day,-2,GETDATE())
30: --明天
31: SELECT DATEADD(Day,1,GETDATE())
32: --后天
33: SELECT DATEADD(Day,2,GETDATE())
34:
35: --上一年
36: SELECT DATEADD(year,-1,GETDATE())
37:
38: --下一年
39: SELECT DATEADD(year,1,GETDATE())
40:
41: --上季度
42: SELECT DATEADD(quarter,-1,GETDATE())
43:
相关新闻>>
最新推荐更多>>>
- 发表评论
-
- 最新评论 更多>>