獲取某一日期所在月份的第一天日期或最後一天日期

獲取指定日期所屬月份的第一天日期:ide

 

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
Source Code

 

獲取指定日期所屬月份的最後一天日期:spa

 

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
Source Code
相關文章
相關標籤/搜索