How to change created_at format

Neon_10 picture Neon_10 · Apr 12, 2015 · Viewed 21.8k times · Source

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?

Answer

Mihail Petkov picture Mihail Petkov · Apr 12, 2015

You can read more about strftime here

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