根据日期计算星期几

declare @weekDay int=0,
        @weekStr varchar(10)='',--星期几
        @startDate datetime ='2022-10-03',
        @Endate datetime ='2022-10-09'
declare @WeekTable table (Date datetime ,weekStr varchar(10),weekDay int) while (@startDate<=@Endate) begin set @weekDay=datepart(weekday,@startDate) set @weekStr=DATENAME(weekday,@startDate) insert into @WeekTable values (@startDate,@weekStr,@weekDay) set @startDate=DATEADD(dd,1,@startDate) end select * from @WeekTable

返回结果

 

posted @ 2022-10-31 11:06  ~且听风吟~  阅读(141)  评论(0编辑  收藏  举报