Thread7 Thread7 - 1 year ago 74
Ruby Question

Converting a date to string representation

I have a date like this: - 7

I tried to convert it into a string:

@last_week = strftime(( - 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 = ( - 7).strftime('%Y-%m-%d')