Joshua
Joshua

Reputation: 2295

Adding a month to a date in T SQL

How can I add one month to a date that I am checking under the where clause?

select *
from Reference
where reference_dt + 1 month

Upvotes: 42

Views: 148449

Answers (6)

SliverNinja - MSFT
SliverNinja - MSFT

Reputation: 31651

SELECT * 
FROM Reference 
WHERE reference_dt = DATEADD(MM, 1, reference_dt)

Upvotes: 2

Icarus
Icarus

Reputation: 63970

SELECT * 
FROM Reference 
WHERE reference_dt = DATEADD(MONTH, 1, another_date_reference)

Upvotes: 81

K. Bob
K. Bob

Reputation: 2688

DateAdd(m, 1, reference_dt)

This will add a month to the column value.

Upvotes: 2

JonH
JonH

Reputation: 33183

You can use DATEADD function with the following syntax

DATEADD (datepart, number, date)

In your case, the code would look like this:

...
WHERE reference_dt = DATEADD(MM, 1, reference_dt)

Upvotes: 17

Purplegoldfish
Purplegoldfish

Reputation: 5294

DATEADD is the way to go with this

See the W3Schools tutorial: http://www.w3schools.com/sql/func_dateadd.asp

Upvotes: 1

LukeH
LukeH

Reputation: 269648

Use DATEADD:

DATEADD(month, 1, reference_dt)

Upvotes: 12

Related Questions