Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to calculate a date after 1 month currentDate

How can I calculate a date after a month of current date.

Example if I have 19/04/2012 I want to get 19/05/2012. Is there any function on sql that allows doing this?

I need to do the same for a year also like 19/04/2012 and set 19/04/2013

Cheers

like image 490
CPM Avatar asked Apr 19 '12 10:04

CPM


2 Answers

You can use DATEADD (datepart , number , date )

as specified here

Examples (thanks to DarrenDavis)

for month:

 select dateadd(m, 1, getdate())

for year:

 select dateadd(YY, 1, getdate())
like image 107
Mithir Avatar answered Oct 03 '22 22:10

Mithir


Use the dateadd() function

SELECT dateadd(mm, 1, '19-Apr-2012')
like image 30
Widor Avatar answered Oct 03 '22 22:10

Widor