I’m displaying user messages on a page and for each user that UserA has sent a message to or received one from has a created_at time.
For each conversation thread I want to display the date of the lastest message in the thread. I’m pulling the created_at time and it’s showing like this:
2012-02-08 09:56:34 UTC
if I add to_date at the end of created_at I can get the date to show this way:
2012-02-08
I’d like to know an easy method for converting either one of those into something like this:
February 8
8 February
February 8th
8th February
and if message not created_at in current year then display the year with the date
e.g. February 8, 2006
Kind regards
Use strftime method to format the date. You can say
created_at.strftime("%B -d")forFebraury 8for example.