Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails: to_date with a month/day/year format

I have a simple question here. I have an instance variable with a created_at. How would I convert it to Month, day, year ~ September, 13, 1987

When I tried = @example.created_at In my view it gives me 1987-09-13

Oddly enough when I do this method in console I get Sun, 13 Sep 1987

  1. How do I turn my variable to month, date, year?
  2. Why does it return something different in console?
like image 330
Alain Goldman Avatar asked Sep 20 '13 20:09

Alain Goldman


1 Answers

You can change how a date is displayed by specifying a format like

@example.created_at.strftime("%B, %d, %Y")
# => "September, 20, 2013" 

Check out various format options here

The display format is different in console and view as the default formats are different.

like image 115
tihom Avatar answered Nov 15 '22 06:11

tihom