寫了2個自定義函數,獲取指定日期所在年份的第一天日期或最後一天的日期: SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO -- -- Author: Insus.NET -- Create date: 2019-05-09 -- Update date ...
寫了2個自定義函數,獲取指定日期所在年份的第一天日期或最後一天的日期:
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_FirstDateOfTheYear] ( @TheYear DATETIME ) RETURNS DATETIME AS BEGIN RETURN DATEADD(YEAR,DATEDIFF(YEAR,0,@TheYear),0) END GOSource 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_LastDateOfTheYear] ( @TheYear DATETIME ) RETURNS DATETIME AS BEGIN RETURN DATEADD(DAY,-1,DATEADD(YEAR,DATEDIFF(YEAR,0,@TheYear) + 1,0)) END GOSource Code
舉例說明: