locked
Subtract Year RRS feed

  • Question

  • User-1499457942 posted

    Hi

      How to subtract a year from below code

    SET @m_date0 = DATEFROMPARTS(@Year, 4, 1)

    Thanks

    Saturday, November 3, 2018 5:33 PM

Answers

  • User61956409 posted

    Hi JagjitSingh,

    How to subtract a year from below code

    SET @m_date0 = DATEFROMPARTS(@Year, 4, 1)

    In your code, we can find that you define and pass year via variable @Year, to subtract a year from it, you can use:

    --YOUR CODE LOGIC
    
    SET @Year = CONVERT(int,  @Year) - 1;
    
    SET @m_date0 = DATEFROMPARTS(@Year, 4, 1)

    Besides, as others mentioned, some functions that could also help modify Date, such as DATEADD(datepart,number,date).

    With Regards,

    Fei Han

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, November 5, 2018 6:06 AM

All replies

  • User452040443 posted

    Hi,

    Try:

    SET @m_date0 = DATEADD(YEAR, -1, DATEFROMPARTS(@Year, 4, 1))

    Hope this help

    Saturday, November 3, 2018 6:12 PM
  • Sunday, November 4, 2018 4:26 AM
  • User61956409 posted

    Hi JagjitSingh,

    How to subtract a year from below code

    SET @m_date0 = DATEFROMPARTS(@Year, 4, 1)

    In your code, we can find that you define and pass year via variable @Year, to subtract a year from it, you can use:

    --YOUR CODE LOGIC
    
    SET @Year = CONVERT(int,  @Year) - 1;
    
    SET @m_date0 = DATEFROMPARTS(@Year, 4, 1)

    Besides, as others mentioned, some functions that could also help modify Date, such as DATEADD(datepart,number,date).

    With Regards,

    Fei Han

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, November 5, 2018 6:06 AM