Thread7 Thread7 - 1 year ago 74
Ruby Question

Converting a date to string representation

I have a date like this:

Date.today - 7


I tried to convert it into a string:

@last_week = strftime((Date.today - 7), '%Y-%m-%d')


But I get the error
"undefined method `strftime'"
. What am I doing wrong?

Answer Source

You can do it like this:

@last_week = (Date.today - 7).strftime('%Y-%m-%d')