MSSQL 获取指定日期所在星期的第一天和最后一天日期 获取指定日期坐在月的第一天和最后一天
ufn_GetWeekFirstAndEndDay 获取指定日期所在星期的第一天和最后一天日期
ALTER FUNCTION [dbo].[ufn_GetWeekFirstAndEndDay](@tmpDate DATETIME)
RETURNS @tmpTable TABLE(
FirstDay DATETIME ,
EndDay DATETIME
)
AS
BEGIN
INSERT INTO @tmpTable
SELECT a.FirstDay,b.EndDay FROM (
SELECT 1 AS ID,DATEADD(wk, DATEDIFF(wk,0,@tmpDate), 0) AS FirstDAy
) a
LEFT JOIN (
SELECT 1 AS ID,DATEADD(wk, DATEDIFF(wk,0,@tmpDate), 6) AS EndDay
) b
ON a.ID = b.ID
RETURN
END
ufn_GetMonthFirstAndEndDay 获取指定日期坐在月的第一天和最后一天
ALTER FUNCTION [dbo].[ufn_GetMonthFirstAndEndDay](@tmpDate DATETIME)
RETURNS @tmpTable TABLE(
FirstDay DATETIME ,
EndDay DATETIME
)
AS
BEGIN
INSERT INTO @tmpTable
SELECT a.FirstDay,b.EndDay FROM (
SELECT 1 AS ID, CONVERT(varchar(10),DATEADD(DAY,-DATEPART(DAY,GETDATE())+1,GETDATE()),23) +‘ 00:00:00‘ AS ‘FirstDay‘
) a
LEFT JOIN (
SELECT 1 AS ID, CONVERT(varchar(10),DATEADD(DAY,-1,DATEADD(MONTH,1,GETDATE()-DAY(GETDATE())+1)),23)+‘ 23:59:59‘ AS ‘EndDay‘
) b
ON a.ID = b.ID
RETURN
END
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。