获取某一日期所在月份的第一天日期或最后一天日期
程序员文章站
2022-09-13 23:54:26
获取指定日期所属月份的第一天日期: 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 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
上一篇: MySQL数据库语句优化