ruby on rails - Converting a month and year to a date -


in rails 4 app receive month , year user make date. new date should 1st of following month i'm not sure on best way tackle this.

at moment have

expiry = date.new(params[:expyear],params[:expmonth].to_i + 1,1) 

but isn't ideal because if entered 12 month approach make month 13 of course doesn't exist (and year wouldn't updated either).

are there useful functions here?

you can this:

year,month = params[:expyear].to_i,params[:expmonth].to_i  date.new(year,month) + 1.month 

or use end_of_month @dax wrote:

date.new(year,month).end_of_month + 1.day 

that resolve problem


Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -

php - Accessing static methods using newly created $obj or using class Name -