获取指定日期所属月份的第一天日期:
![](https://i-blog.csdnimg.cn/blog_migrate/8f900a89c6347c561fdf2122f13be562.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/961ddebeb323a10fe0623af514929fc1.gif)
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
获取指定日期所属月份的最后一天日期:
![](https://i-blog.csdnimg.cn/blog_migrate/8f900a89c6347c561fdf2122f13be562.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/961ddebeb323a10fe0623af514929fc1.gif)
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