想知道某一天是星期几,下面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
举个例子: