How do I add months to a CURRENT_TIMESTAMP in SQL?

后端 未结 3 1004
生来不讨喜
生来不讨喜 2021-01-01 16:35

How can I add months to the CURRENT_TIMESTAMP in SQL Server?

The solution probably lies in DATEADD() but this works with a date only, not a datetime.

Thanks.

相关标签:
3条回答
  • 2021-01-01 17:12

    The Current_Timestamp is the ansi equivalent of GetDate() in SQL, so it is perfetly acceptable to use within a DateAdd function.

    select dateadd(m,3,current_timestamp)
    

    Adds 3 months to the current timestamp.

    0 讨论(0)
  • 2021-01-01 17:15

    This works perfectly fine

    SELECT DATEADD(month,1,CURRENT_TIMESTAMP)
    

    From DATEADD (Transact-SQL)

    date

    Is an expression that can be resolved to a time, date, smalldatetime, datetime, datetime2, or datetimeoffset value.

    0 讨论(0)
  • 2021-01-01 17:24

    add_months(Tablename,No.of months)

    0 讨论(0)
提交回复
热议问题