求工作日历是星期几的 的存贮过程或者函数?
求工作日历是星期几的存贮过程或者函数?
如 2007-03-19 周一
时间范围 2006-01-01
到 2007-12-31
之间!
------解决方案--------------------SELECT DATENAME(weekday, GETDATE())
------解决方案--------------------Create Procedure SP_TEST
(@StartDate DateTime,
@EndDate DateTime)
As
Begin
Select Top 1000 Identity(Int, 0, 1) As ID Into #T from Sysobjects A, Sysobjects B
Select
Convert(Varchar(10), 日期, 120) As 日期,
DateName(Weekday, 日期) As [WeekDay]
From
(
Select
DateAdd(dd, ID, @StartDate) As 日期 From #T Where ID <= DateDiff(dd, @StartDate, @EndDate)
) A
Drop Table #T
End
GO
EXEC SP_TEST '2007-01-01 ', '2007-12-31 '
GO
Drop Procedure SP_TEST
------解决方案--------------------declare @begindate datetime
declare @enddate datetime
select @begindate= '2006-01-01 ',@enddate= '2007-12-31 '
while @begindate <=@enddate
begin
print convert(char(10),@begindate,120)+ '是: '+DATENAME(weekday, @begindate)
select @begindate=dateadd(day,1,@begindate)
end
------解决方案--------------------利用函数datepart(weekday,getdate())可以获取当前日期为星期几
例如:
Select datepart(weekday,getdate())
返回值为2,表示今天是星期一(因为每周的第一天是星期日,你可以通过设置改变每周的第一天为星期一)