Skip to Main Content

Breadcrumb

Question and Answer

Connor McDonald

Thanks for the question, Mohannad.

Asked: July 16, 2016 - 11:14 am UTC

Last updated: July 17, 2016 - 12:33 am UTC

Version: 11g

Viewed 1000+ times

You Asked

Hi Guys,


I am just a little bit confused regarding the following :

select add_months(to_date('30/01/2016','DD/MM/YYYY'),1) from dual

Result is : 29/02/2016, shouldn't it be 28/02/2016 ??

Thanks
Mohannad

and Connor said...

The way ADD_MONTHS works is:

a) Take the *month* component and move it forward

30-01-2016 becomes 30-02-2016

b) If the result is not a valid date, then roll the *day* backwards

30-02-2016 becomes 29-02-2016

Hope this helps.

Rating

  (1 rating)

Is this answer out of date? If it is, please let us know via a Comment

Comments

thanks awesine

A reader, July 17, 2016 - 8:47 am UTC