zoukankan      html  css  js  c++  java
  • 根据当前时间获取会计月开始时间 结束时间

    -- =============================================
    -- Author: hehai
    -- Create date: 2015-11-19 11:01:01
    -- Description: 判定时间是否在时间区间范围内。
    -- =============================================
    CREATE FUNCTION fn_pdsj
    (
    @date DATETIME, -- 时间
    @date_Range_min DATETIME, -- 时间区间(起始值)
    @date_Range_max DATETIME -- 时间区间(结束值)
    )
    RETURNS BIT
    AS
    BEGIN
    DECLARE @return BIT
    SELECT @return=1 FROM sys.objects WHERE @date BETWEEN @date_Range_min AND @date_Range_max
    IF @return IS NULL SET @return=0
    RETURN @return -- @min_seconds>0 AND @max_seconds>0
    END

    GO

    CREATE FUNCTION [dbo].[fn_getyu]
    ( @datea VARCHAR(10),
    @pda VARCHAR(2)--0时开始时间 1时结束时间
    )
    RETURNS date
    AS
    BEGIN
    declare @daa date
    declare @kssj date
    declare @jssj date
    declare @y VARCHAR(2)
    declare @pd VARCHAR(2)
    set @y=MONTH(@datea)
    DECLARE @date_Range_min DATETIME=cast(YEAR(@datea) as VARCHAR(4))+'-'+cast(month(@datea) as VARCHAR(2))+'-26'
    DECLARE @date_Range_max DATETIME=dateadd(d,-day(@datea),dateadd(m,1,@datea))
    SELECT @pd= jbcsj.dbo.fn_pdsj(@datea,@date_Range_min,@date_Range_max)
    IF @pd=0
    BEGIN
    IF @y=1
    BEGIN
    set @kssj=dateadd(dd,-6,DATEADD(yy, DATEDIFF(yy,0,getdate()), 0))
    END
    ELSE
    BEGIN
    set @kssj=cast(YEAR(@datea) as VARCHAR(4))+'-'+cast(month(dateadd(month, -1, @datea)) as VARCHAR(2))+'-26'
    END
    set @jssj=cast(YEAR(@datea) as VARCHAR(4))+'-'+cast(month(@datea) as VARCHAR(2))+'-26'
    END
    ELSE
    BEGIN
    set @kssj=cast(YEAR(@datea) as VARCHAR(4))+'-'+cast(month(@datea) as VARCHAR(2))+'-26'
    set @jssj=cast(YEAR(@datea) as VARCHAR(4))+'-'+cast(month(@datea)+1 as VARCHAR(2))+'-26'
    END
    IF @pda=0
    BEGIN
    set @daa=@kssj
    END
    ELSE
    BEGIN
    set @daa=@jssj
    END

    RETURN @daa
    END
    GO

    declare @daa date='2019-11-24'

    SELECT @kssj= jbcsj.dbo.fn_getyu(@datea,0)
    SELECT @jssj= jbcsj.dbo.fn_getyu(@datea,1)
    SELECT @kssj,@jssj

  • 相关阅读:
    [题解] LuoguP1587 [NOI2016]循环之美
    [题解] LuoguP3705 [SDOI2017]新生舞会
    [题解] LuoguP3702 [SDOI2017]序列计数
    [题解] LuoguP6476 [NOI Online 2 提高组]涂色游戏
    [题解] LuoguP4240 毒瘤之神的考验
    [题解] LuoguP6156简单题
    [题解] LuoguP6055 [RC-02] GCD
    [题解] LuoguP5050 【模板】多项式多点求值
    AtCoder Grand Contest 028题解
    Codeforces Round #421 (Div. 1) 题解
  • 原文地址:https://www.cnblogs.com/lydg/p/11905624.html
Copyright © 2011-2022 走看看