Adding a month to a date in T SQL

2019-04-03 01:49发布

问题:

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

e.g.:

select *
from Reference
where reference_dt + 1 month

回答1:

select * from Reference where reference_dt = DateAdd(month,1,another_date_reference)


回答2:

Look at DATEADD

SELECT DATEADD(mm, 1, OrderDate)AS TimeFrame

Here's the MSDN

In your case

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



回答3:

Use DATEADD:

DATEADD(month, 1, reference_dt)


回答4:

DateAdd(m,1,reference_dt)

will add a month to the column value



回答5:

select * from Reference where reference_dt = DATEADD(mm, 1, reference_dt)


回答6:

DATEADD is the way to go with this

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