獲取指定日期所屬月份的第一天日期: SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO -- -- Author: Insus.NET -- Create date: 2019-05-09 -- Update date: 2019-05-09 -- De ...
獲取指定日期所屬月份的第一天日期:
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 GOSource Code
獲取指定日期所屬月份的最後一天日期:
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)) ENDSource Code