How can I calculate the date after the month of the current date.
Example if I have 04/19/2012 I want to receive 05/19/2012. Is there any function in sql that allows this?
I need to do the same for the year as on 04/19/2012, and set 04/19/2013
Greetings
You can use DATEADD (datepart, number, date)
as indicated here
Examples (thanks DarrenDavis)
per month:
select dateadd(m, 1, getdate())
per year:
select dateadd(YY, 1, getdate())
Use dateadd () function
SELECT dateadd(mm, 1, '19-Apr-2012')
To add 1 month to the current date:
SELECT DATEADD(m, 1, GETDATE())
To add 1 year to the current date:
SELECT DATEADD(YY, 1, GETDATE())
For additional arguments see:
http://msdn.microsoft.com/en-us/library/ms186819.aspx
You can use DateAdd:
select dateadd(m, 1, getdate()) select dateadd(yy, 1, getdate())
Internet search for other period indicators such as hour, minute, etc.
Something like this should do the job
SELECT DATEADD (month, 1, '2012-04-19')
during a year
SELECT DATEADD (year, 1, '2012-04-19)
You can use this request for 1 month in advance. This query works fine in oracle.
select add_months(trunc(sysdate),1) from dual;
Use this request for 1 year in advance
select add_months(trunc(sysdate),12) from dual;