ruby-on-railsdateactiverecorddate-formatdatecreated

How to change created_at format


This should be a simple thing. Well, Im sure it should be simple, this is rails.

The problem is: in the model all data has a field created_at. to retrieve this info in the view I use a block, where is a line t.created_at.

It shows me a result like 2015-04-12 11:04:44 UTC

Which method should I use to show this date as 2015-04-12? As I suppose it should be something like that: t.created_at.date_only

Could you help me?


Solution

  • You can read more about strftime here

    t.created_at.strftime("%Y-%m-%d")