Forum: Ruby on Rails Transforming DateTime in this format: Fri Mar 13 13:00:52 -0700 2009

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Lee D'oéjgi (Guest)
on 2009-03-14 14:44
(Received via mailing list)
I'm trying to reformat the following DateTime: 'Fri Mar 13 13:00:52
-0700
2009' to be '2009-03-13 13:00:42', but can't quite seem to get it. I've
tried strftime('%a %b %d %H %M %S -0700 %Y') amongst other things and
google
isn't helping...

Any advice?
senthil raja (Guest)
on 2009-03-14 18:48
(Received via mailing list)
You have to use double quotes

use strftime("%Y-%m-%d %H:%M:%S")

Regards
Senthil Raja S P
Colin L. (Guest)
on 2009-03-14 19:22
(Received via mailing list)
2009/3/14 senthil raja <removed_email_address@domain.invalid>

> You have to use double quotes
>
> use strftime("%Y-%m-%d %H:%M:%S")
>

It is not necessary to use double quotes, single quotes are ok. It is
only a
string.


>> isn't helping...
>>
>
What is it that you are calling strftime on (show us some code), and
what
result do you get when you call it as you have shown?

Colin
senthil raja (Guest)
on 2009-03-16 06:59
(Received via mailing list)
For eg) Time.now.strftime("%Y-%m-%d %H:%M:%S")

will results 2009-03-16 10:00:42
Priya B. (Guest)
on 2009-03-16 10:32
Lee D'oéjgi wrote:
> I'm trying to reformat the following DateTime: 'Fri Mar 13 13:00:52
> -0700
> 2009' to be '2009-03-13 13:00:42', but can't quite seem to get it. I've
> tried strftime('%a %b %d %H %M %S -0700 %Y') amongst other things and
> google
> isn't helping...
>
> Any advice?

If the value is array or string, first convert that into datetime format
and try with using strftime(needed format).
This topic is locked and can not be replied to.