获取星期几的名称
程序员文章站
2023-12-14 19:27:34
udf_weekdayname 复制代码 代码如下: create function [dbo].[udf_weekdayname] ( ) returns @weekda...
udf_weekdayname
create function [dbo].[udf_weekdayname]
(
)
returns @weekdayname table([id] int,[weekdayname] nvarchar(15))
as
begin
insert into @weekdayname ([id],[weekdayname]) values (0,'saturday'),(1,'sunday'),(2,'monday'),(3,'tuesday'),(4,'wednesday'),(5,'thursday'),(6,'friday')
return
end
udf_weekdaynameofdate
create function [dbo].[udf_weekdaynameofdate]
(
@date datetime
)
returns nvarchar(10)
begin
return
case (datepart(dw, @date) + @@datefirst) % 7
when 0 then 'saturday'
when 1 then 'sunday'
when 2 then 'monday'
when 3 then 'tuesday'
when 4 then 'wednesday'
when 5 then 'thursday'
when 6 then 'friday'
end
end
复制代码 代码如下:
create function [dbo].[udf_weekdayname]
(
)
returns @weekdayname table([id] int,[weekdayname] nvarchar(15))
as
begin
insert into @weekdayname ([id],[weekdayname]) values (0,'saturday'),(1,'sunday'),(2,'monday'),(3,'tuesday'),(4,'wednesday'),(5,'thursday'),(6,'friday')
return
end
udf_weekdaynameofdate
复制代码 代码如下:
create function [dbo].[udf_weekdaynameofdate]
(
@date datetime
)
returns nvarchar(10)
begin
return
case (datepart(dw, @date) + @@datefirst) % 7
when 0 then 'saturday'
when 1 then 'sunday'
when 2 then 'monday'
when 3 then 'tuesday'
when 4 then 'wednesday'
when 5 then 'thursday'
when 6 then 'friday'
end
end