# Transforming DateTime in this format: Fri Mar 13 13:00:52 -0700 2009

**URL:** <https://www.ruby-forum.com/t/transforming-datetime-in-this-format-fri-mar-13-1352-0700-2009/162843>\
**Category:** Rails\
**Created:** [March 14, 2009, 1:44pm UTC](https://www.ruby-forum.com/t/transforming-datetime-in-this-format-fri-mar-13-1352-0700-2009/162843 "2009-03-14T13:44:19Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Lee\_DSoSSSSjgi](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/c67d28/32.png) [@Lee\_DSoSSSSjgi](https://www.ruby-forum.com/u/Lee_DSoSSSSjgi)\
**Post date:** [March 14, 2009, 1:44pm UTC](https://www.ruby-forum.com/t/transforming-datetime-in-this-format-fri-mar-13-1352-0700-2009/162843/1 "2009-03-14T13:44:19Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![Lee\_DSoSSSSjgi](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/c67d28/32.png) [@Lee\_DSoSSSSjgi](https://www.ruby-forum.com/u/Lee_DSoSSSSjgi)\
**Post date:** [March 14, 2009, 5:48pm UTC](https://www.ruby-forum.com/t/transforming-datetime-in-this-format-fri-mar-13-1352-0700-2009/162843/2 "2009-03-14T17:48:07Z")

</div>

You have to use double quotes

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

Regards  
Senthil Raja S P

---

<div class="post-metadata">

**Author:** ![Lee\_DSoSSSSjgi](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/c67d28/32.png) [@Lee\_DSoSSSSjgi](https://www.ruby-forum.com/u/Lee_DSoSSSSjgi)\
**Post date:** [March 14, 2009, 6:22pm UTC](https://www.ruby-forum.com/t/transforming-datetime-in-this-format-fri-mar-13-1352-0700-2009/162843/3 "2009-03-14T18:22:45Z")

</div>

2009/3/14 senthil raja [removed\_email\_address@domain.invalid](mailto: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

---

<div class="post-metadata">

**Author:** ![Lee\_DSoSSSSjgi](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/c67d28/32.png) [@Lee\_DSoSSSSjgi](https://www.ruby-forum.com/u/Lee_DSoSSSSjgi)\
**Post date:** [March 16, 2009, 5:59am UTC](https://www.ruby-forum.com/t/transforming-datetime-in-this-format-fri-mar-13-1352-0700-2009/162843/4 "2009-03-16T05:59:44Z")

</div>

For eg) Time.now.strftime("%Y-%m-%d %H:%M:%S")

will results 2009-03-16 10:00:42

---

<div class="post-metadata">

**Author:** ![Lee\_DSoSSSSjgi](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/c67d28/32.png) [@Lee\_DSoSSSSjgi](https://www.ruby-forum.com/u/Lee_DSoSSSSjgi)\
**Post date:** [March 16, 2009, 9:32am UTC](https://www.ruby-forum.com/t/transforming-datetime-in-this-format-fri-mar-13-1352-0700-2009/162843/5 "2009-03-16T09:32:52Z")

</div>

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).
