Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add months in date with rails [closed]

For example: I am inserting date 2011-06-01 (format mm/dd/yyyy) and now I want to add 8 months to this date. I want the result to be 2012-02-01.

So when adding months, the year may also increase.

like image 286
Angel Portillo Avatar asked Oct 23 '25 19:10

Angel Portillo


1 Answers

Rails provides for + n.days, n.months, etc.

my_date + 8.months

This is an ActiveRecord, not a Ruby thing, though. So make sure it's loading thru Rails.

like image 84
Brian Wagner Avatar answered Oct 26 '25 09:10

Brian Wagner



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!