sql 日期-周-月

1 declare @beginDate varchar(50)  
2 set @beginDate = '2012-07-04'  
3 select datepart(week,@beginDate) as 年内的第几周
4 select dateadd(day,1-(datepart(weekday,@beginDate)),@beginDate) as 本周开始日期--(注意:每周是从周日开始,周一结束)
5 select dateadd(day,1-(datepart(weekday,@beginDate))+6,@beginDate) as 本周截至日期
6 select datename(weekday, @beginDate) as 当天是星期几
7 SELECT DATEADD(mm, DATEDIFF(mm ,0,@beginDate), 0) as 当前日期月份第一天
8 SELECT dateadd(ms,-3,DATEADD(mm, DATEDIFF(m,0,@beginDate)+1, 0)) as 当前日期月份最后一天--(带毫秒)

可根据需要修改日期参数

posted @ 2012-07-27 09:03  小蜗  阅读(200)  评论(0编辑  收藏  举报