user1549905
user1549905

Reputation: 13

Converting string to date

I have a database table named "events" with a column named "date." Entries under that in the format of "Sunday, August 05, 2012". I show it using events.date. How would I convert that string to a date with integers (like 8/5/12), and show it that way?

Upvotes: 1

Views: 98

Answers (3)

abhas
abhas

Reputation: 5213

try this

Date.parse("Sunday, August 05, 2012").strftime("%m/%d/%y")

Upvotes: 1

bender
bender

Reputation: 1428

Actually, for exact result, i.e. "8/5/12", you should try this:

Date.parse("Sunday, August 05, 2012").strftime("%1m/%1d/%y")

Upvotes: 3

phoet
phoet

Reputation: 18835

you would use rails i18n features for this: http://guides.rubyonrails.org/i18n.html#adding-date-time-formats

Upvotes: 1

Related Questions