ruby - How can I change the day in a date string? -


i have string variable date this:

@date = "2016-09-01" 

and have variable day this:

@day = 5 

how can change day of date using @day value?

i need result:

@date = "2016-09-05" 

if want work plain string, can replace last 2 characters date string this:

@date[-2..-1] = @day.to_s.rjust(2, "0") 

Comments