Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I add months to a CURRENT_TIMESTAMP in SQL?

Tags:

sql

sql-server

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.

like image 973
Gerrie Schenck Avatar asked Mar 11 '10 10:03

Gerrie Schenck


2 Answers

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.

like image 37
Andrew Avatar answered Nov 12 '22 19:11

Andrew


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.

like image 96
Adriaan Stander Avatar answered Nov 12 '22 19:11

Adriaan Stander