Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Transforming Datetime into month, day and year?

I can't seem to find this and I feel like it should be easy. In Ruby on Rails, how do I take:

2010-06-14 19:01:00 UTC 

and turn it into

June 14th, 2010 

Can I not just use a helper in the view?

like image 861
bgadoci Avatar asked Jun 15 '10 05:06

bgadoci


People also ask

How do you convert datetime to mm dd yyyy?

For the data load to convert the date to 'yyyymmdd' format, I will use CONVERT(CHAR(8), TheDate, 112). Format 112 is the ISO standard for yyyymmdd.

How do you convert date to month and year in SQL?

Here is one method: select convert(date, cast(startyear*10000 + startmon*100 + 1 as varchar(8)), 112) . . .


1 Answers

I don't know for

June 14th, 2010 

But if you want

June 14, 2010 

Ref how do i get name of the month in ruby on Rails? or this

Just do

@date = Time.now @date.strftime("%B %d, %Y") 

And for suffix use following

@date.strftime("%B #{@date.day.ordinalize}, %Y") # >>> Gives `June 18th, 2010` 
like image 198
Salil Avatar answered Sep 28 '22 17:09

Salil