Formatting dates in rails templates using strftime()

Posted by paul Tue, 23 Aug 2005 14:07:38 GMT

Recently I needed to be able to format a date that I had retrieved from the database into something more readable. In smarty one would do something like $date|date_format but I could not find anything like that in ruby.

Then someone pointed out that the date field in the database would be recognised as such and would be a date object in my View.

As the date is a Date object I can use strftime() to reformat the date any way I want to. eg. @event.start_date.strftime("%d %B %Y")

Comments

Leave a response

Comments