Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ruby DateTime format: How can I get 1st, 2nd, 3rd, 4th?

First of all, it doesn't seem that the DateTime format variables are documented anywhere so a +1 to anyone who can show this to me in rubydocs. Second of all, when looking at the Date.strftime function code, I don't see anything that can let me do something like:

Thursday, September 9th 2010

Does anyone know if this is possible?

like image 313
aarona Avatar asked Sep 09 '10 19:09

aarona


1 Answers

You might want to take a look here.

To summarize

time = DateTime.now
time.strftime("%A, %B #{time.day.ordinalize} %Y")

Note that you are running in plain Ruby (2.0) you'll need to call:

require 'active_support/core_ext/integer/inflections'
like image 177
aNoble Avatar answered Oct 23 '22 07:10

aNoble