前一天或后一天

时间:2022-11-20 08:06:20

Insus.NET把它们写成自定义函数,再程序中直接套用即可。

前一天:

前一天或后一天

 

前一天或后一天前一天或后一天
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:      Insus.NET
-- Create date: 2019-05-15
-- Update date: 2019-05-15
-- Description: 前一天
-- =============================================
CREATE FUNCTION [dbo].[svf_TheDayBefore]
(
    @Date DATETIME
)
RETURNS DATETIME
AS 
BEGIN 
    RETURN DATEADD(d,-1,@Date)
END
GO
Source Code

 

后一天:

前一天或后一天

 

前一天或后一天前一天或后一天
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:      Insus.NET
-- Create date: 2019-05-15
-- Update date: 2019-05-15
-- Description: 后一天
-- =============================================
CREATE FUNCTION [dbo].[svf_TheDayAfter]
(
    @Date DATETIME
)
RETURNS DATETIME
AS 
BEGIN 
    RETURN DATEADD(d,1,@Date)
END
GO
Source Code

 

如果获取昨天或明天日期,传入今天日期进去即可:

前一天或后一天