ALTER FUNCTION [dbo].[GetWeekDay]
(
@Year INT, @Month INT ,@Day INT
)
RETURNS INT
AS
BEGIN DECLARE @date DATETIME= DATEFROMPARTS(@Year,@Month,@Day);
DECLARE @weekday INT =0;
--select @@datefirst
--SELECT alias, * from master..syslanguages
--SELECT DATEPART(WEEKDAY,'2018-11-17')
IF @@DATEFIRST =7---从周日开始到周六 1,2,3,4,5,6,7
BEGIN
SET @weekday= 7-(8- DATEPART(WEEKDAY,@date) )%7 ;
END ELSE -----1---从周一开始到周日 1,2,3,4,5,6,7
BEGIN
SET @weekday= DATEPART(WEEKDAY,@date) ;
END
--SELECT 7-(8- DATEPART(WEEKDAY,'2018-11-23') )%7
--SELECT 7-(8- DATEPART(WEEKDAY,'2018-11-24') )%7
--SELECT 7-(8- DATEPART(WEEKDAY,'2018-11-25') )%7
--SELECT dbo.GetWeekDay(2018,11,23)
--SELECT dbo.GetWeekDay(2018,11,24)
--SELECT dbo.GetWeekDay(2018,11,25)
--SELECT dbo.GetWeekDay(2018,11,26)
--SELECT dbo.GetWeekDay(2018,11,20)
--SELECT dbo.GetWeekDay(2018,11,21)
--SELECT dbo.GetWeekDay(2018,11,22)
--SELECT dbo.GetWeekDay(2018,11,23)
--SELECT dbo.GetWeekDay(2018,11,24)
--SELECT dbo.GetWeekDay(2018,11,25)
--SELECT dbo.GetWeekDay(2018,11,26)
RETURN @weekday
END