求知某一天是星期几

想知道某一天是星期几,下面Insus.NET写了一个函数,具体是怎样,可以细细研究。

 

SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

-- =============================================
-- Author:      Insus.NET
-- Create date: 2019-05-15
-- Update date: 2019-05-15
-- Description: 获取某一天是星期几
-- =============================================
CREATE FUNCTION [dbo].[svf_DayOfWeek]
(
    @Date DATETIME
)
RETURNS INT
AS 
BEGIN                                                           
    DECLARE @D INT = (@@DATEFIRST - 1) + DATEPART(dw, @Date)
    RETURN @D - CASE WHEN @D > 7 THEN 7 ELSE 0 END 
END
GO
Source Code

 

举个例子:

 

posted @ 2019-05-15 10:17  Insus.NET  阅读(396)  评论(0编辑  收藏  举报