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
Post a Comment