我输入日期时需要一周的开始日期和结束日期。
注意:周必须从SUNDAY开始,到SATURDAY结束
答案 0 :(得分:0)
Select DATEADD(WEEK,DATEDIFF(WEEK,0,GETDATE()),0)-1 'Start date',
DATEADD(WEEK,DATEDIFF(WEEK,0,GETDATE())+1,0)-2 'End Date'
答案 1 :(得分:0)
根据你的逻辑"周从星期日开始,到星期六结束"
select "start_of_week" = dateadd(week, datediff(week,0, GETDATE()),-1);
select "end_of_week" = dateadd(week, datediff(week,0, GETDATE()),5);
答案 2 :(得分:0)
试试这个:
SELECT GETDATE()-DATEPART(WEEKDAY,GETDATE())+1 AS StartOfWeek, GETDATE()+(7-DATEPART(WEEKDAY,GETDATE())) AS EndOfWeek
此处,DATEPART(WEEKDAY,GETDATE())
返回4(工作日编号) - [今天 2014年6月18日]