- Declare @Week varchar(20)
- Declare @FirstDay varchar(20)
- Declare @LastDay varchar(20)
- select @Week='200851'
- Declare @FirstYearDay Smalldatetime,@intWeekNum Int,@intDay int,@Day SmallDateTime
- SELECT @FirstYearDay=Convert(Smalldatetime,Left(@Week,4)+'/1/1'),@intWeekNum=Right(@Week,2)
- Select @intDay=(@intWeekNum-datepart(week,@FirstYearDay))*7
- Select @Day=DateAdd(day,@intDay,@FirstYearDay)
- Select @FirstDay=DateAdd(Day,1-DatePart(WeekDay,@Day),@Day),@LastDay=DateAdd(Day,7-DatePart(WeekDay,@Day),@Day)
- Select @FirstDay,@LastDay,DatePart(WeekDay,@FirstDay),DatePart(WeekDay,@LastDay),DatePart(Week,@FirstDay),DatePart(Week,@LastDay)
- /*
- -------------------- -------------------- ----------- ----------- ----------- -----------
- Dec 14 2008 12:00AM Dec 20 2008 12:00AM 1 7 51 51
- (1 row(s) affected)
- */
取年份某周的開始日期和結束日期
最新推荐文章于 2023-03-01 13:44:34 发布