Date function to add year, month and week

Kenny Gua 431 Reputation points
2022-02-01T21:53:13.027+00:00

Hi- I have to add no. of month and no. of week in the following 2nd and 3rd query to get the result.

SELECT DateADD(DD, -0 , DateADD(YEAR, +64.0, '1957-02-23 00:00:00.000'))
SELECT DateADD(DD, -0 , DateADD(YEAR, +64, '1957-02-23 00:00:00.000')) + month (6)
SELECT DateADD(DD, -0 , DateADD(YEAR, +64, '1957-02-23 00:00:00.000')) + month (6) + week (4)

Expected result for adding 64 yr: 2021-02-23
Expected result for adding 64 yr+ six month: 2021-08-23
Expected result for adding 64 yr+ six month + four weeks: 2021-09-23 approx

SQL Server
SQL Server
A family of Microsoft relational database management and analysis systems for e-commerce, line-of-business, and data warehousing solutions.
13,361 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Erland Sommarskog 107.2K Reputation points
    2022-02-01T22:20:48.81+00:00

    Boring as it may, this is how you do it:

    SELECT dateadd(WEEK, 4, 
               dateadd(Month, 6, 
                 dateadd(YEAR, 64, '1957-02-23 00:00:00.000')))
    
    0 comments No comments

  2. YufeiShao-msft 7,091 Reputation points
    2022-02-02T06:35:09.613+00:00

    Hi @Kenny Gua ,

    2021-08-23 00:00:00.000:

    SELECT dateadd(MONTH, 6,  
              dateadd(YEAR, 64, '1957-02-23 00:00:00.000'))  
    

    2021-09-20 00:00:00.000:

    SELECT dateadd(WEEK, 4,   
               dateadd(Month, 6,   
                 dateadd(YEAR, 64, '1957-02-23 00:00:00.000')))  
    

    -------------

    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments