获取某一日期所在月份的第一天日期或最后一天日期

获取指定日期所属月份的第一天日期:

 

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

 

获取指定日期所属月份的最后一天日期:

 

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

 

posted @ 2019-05-09 22:53  Insus.NET  阅读(3519)  评论(0编辑  收藏  举报