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
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.
SELECT *
FROM Reference
WHERE reference_dt = DATEADD(MONTH, 1, another_date_reference)
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)
Use DATEADD
:
DATEADD(month, 1, reference_dt)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With