获取星期几的名称

前端之家收集整理的这篇文章主要介绍了获取星期几的名称前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

udf_WeekDayName
<div class="codetitle"><a style="CURSOR: pointer" data="73475" class="copybut" id="copybut73475" onclick="doCopy('code73475')"> 代码如下:

<div class="codebody" id="code73475">
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
<div class="codetitle"><a style="CURSOR: pointer" data="65189" class="copybut" id="copybut65189" onclick="doCopy('code65189')"> 代码如下:
<div class="codebody" id="code65189">
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

原文链接:https://www.f2er.com/mssql/63867.html

猜你在找的MsSQL相关文章