获取指定日期所属月份的第一天日期:
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