获取某一日期所在月份的第一天日期或最后一天日期
获取指定日期所属月份的第一天日期:
SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO -- ============================================= -- Author: Insus.NET -- Create date: 2019-05-09 -- Update date: 2019-05-09 -- Description: 获取指定日期所属月份的第一天日期 -- ============================================= ALTER FUNCTION [dbo].[svf_FirstDayOfTheMonth] ( @TheDate DATETIME ) RETURNS DATETIME AS BEGIN RETURN DATEADD(MONTH,DATEDIFF(MONTH,0,@TheDate),0) END GO
获取指定日期所属月份的最后一天日期:
SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO -- ============================================= -- Author: Insus.NET -- Create date: 2019-05-09 -- Update date: 2019-05-09 -- Description: 获取指定日期所属月份的最后一天日期 -- ============================================= CREATE FUNCTION [dbo].[svf_LastDayOfTheMonth] ( @TheDate DATETIME ) RETURNS DATETIME AS BEGIN RETURN DATEADD(DAY,-1,DATEADD(MONTH,DATEDIFF(MONTH,0,@TheDate) + 1,0)) END
正文到此结束