Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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
like image 975
Joshua Avatar asked Nov 01 '11 13:11

Joshua


People also ask

How do I convert a date to a month in SQL?

To get a month from a date field in SQL Server, use the MONTH() function. This function takes only one argument – the date. This can be a date or date and time data type.


3 Answers

SELECT * 
FROM Reference 
WHERE reference_dt = DATEADD(MONTH, 1, another_date_reference)
like image 155
Icarus Avatar answered Oct 04 '22 06:10

Icarus


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)
like image 29
JonH Avatar answered Oct 04 '22 06:10

JonH


Use DATEADD:

DATEADD(month, 1, reference_dt)
like image 35
LukeH Avatar answered Oct 04 '22 06:10

LukeH