Rails undefined method `strftime' for "2013-03-06":String

Colin picture Colin · Apr 1, 2013 · Viewed 21.2k times · Source

I am getting the error

undefined method `strftime' for "2013-03-06":String

when trying to display a date normally (June Sunday 3, 2013 or something similar) from the string 2013-03-06 using strftime.

The line that does this in my index.html.erb and looks like this

<td><%= task.duedate.strftime("%B %e, %Y") %></td>

I am just learning Rails so I am sure it is just a stupid beginners error, any help would be appreciated. Thank you

Answer

hellaxe picture hellaxe · Apr 1, 2013

It looks like your duedate is a string, when strftime is a method for Time/Date class. You can try this:

Date.parse(task.duedate).strftime("%B %e, %Y")