SQL Server 2005 | Add days, months and years to GetDate()

To get the current date in Sql Server queries and stored procedures, you use the GetDate() method. But what about to add a day or two to the current date, or add a month or years? To do it, you use the following query:

Add One Day

SELECT DateAdd(dd, 1, GetDate())

Add One Month

SELECT DateAdd(mm, 1, GetDate())

Add One Year

SELECT DateAdd(yy, 1, GetDate())

To subtract a day, month or year, instead of 1, insert -1, thus to subtract 1 month use the following:

SELECT DateAdd(mm, -1, GetDate())

References here

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s