# Ruby date conversion

**URL:** <https://rubytalk.org/t/ruby-date-conversion/37277>\
**Category:** ruby-talk\
**Created:** [30 April 2007 09:39 UTC](https://rubytalk.org/t/ruby-date-conversion/37277 "2007-04-30T09:39:17Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Singeo](https://avatars.discourse-cdn.com/v4/letter/s/3ec8ea/32.png) [@Singeo](https://rubytalk.org/u/Singeo)\
**Post date:** [30 April 2007 09:39 UTC](https://rubytalk.org/t/ruby-date-conversion/37277/1 "2007-04-30T09:39:17Z")

</div>

Hi, I have a text file with dates stored in the following format:

30/04/07 16:52:00 +0800

I need to convert these dates to RFC-822 so the above would become:

Mon, 30 Apr 2002 16:52:00 +0800

Can someone help me with the Ruby code required to do this? I've bveen  
trying to do it using Time.parse but with no success.

Thanks

---

<div class="post-metadata">

**Author:** ![Forum](https://avatars.discourse-cdn.com/v4/letter/f/43a26b/32.png) [@Forum](https://rubytalk.org/u/Forum)\
**Post date:** [30 April 2007 10:47 UTC](https://rubytalk.org/t/ruby-date-conversion/37277/2 "2007-04-30T10:47:45Z")

</div>

I do this as lazily as possible:

irb(main):009:0\> x="30/04/07 16:52:00 +0800"  
=\> "30/04/07 16:52:00 +0800"  
irb(main):010:0\> y,rest = x.split(/\s+/,2)  
=\> ["30/04/07", "16:52:00 +0800"]  
irb(main):011:0\> s=Date.strptime(y,"%y/%m/%d")  
=\> #\<Date: 4925197/2,0,2299161\>  
irb(main):024:0\> s.strftime("%a, %d %b %y") \<\< rest  
=\> "Sun, 07 Apr 3016:52:00 +0800"

HTH  
Robert

> **···**
>
> On 4/30/07, Singeo \<singeo.sg@gmail.com\> wrote:
> 
> > Hi, I have a text file with dates stored in the following format:
> > 
> > 30/04/07 16:52:00 +0800
> > 
> > I need to convert these dates to RFC-822 so the above would become:
> > 
> > Mon, 30 Apr 2002 16:52:00 +0800
> > 
> > Can someone help me with the Ruby code required to do this? I've bveen  
> > trying to do it using Time.parse but with no success.
> > 
> > Thanks
> 
> --  
> You see things; and you say Why?  
> But I dream things that never were; and I say Why not?  
> -- George Bernard Shaw
