Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

like image 382
Colin Avatar asked Mar 31 '13 23:03

Colin


2 Answers

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")
like image 195
hellaxe Avatar answered Dec 08 '22 07:12

hellaxe


This solved the issue for me:

Date.created_at.try(:strftime, ("%B %e, %Y"))

Hope this helps!

like image 30
Jordan Avatar answered Dec 08 '22 08:12

Jordan