Date format conversion

Now i facing the date format in my
database. I am using mysql as my database then the datetime format is
2008-06-04 15:17:55. But my datetime format is like this Fri May 23
16:43:28 +0800 2008. So when i execute it say incorrect datetime value.
how do i change the date_format in rails.

I did not save in any variable like @email_date_time so i cannot do


Because the datetime is i retrieved from
internet email and save it into a text file. So there isn’t any variable
assign to it.
Fri May 23 16:43:28 +0800 2008 is a rfc822 format.
So how can i change mysql date format to rfc822 date_format in rails.



Time.parse(“Fri May 23 16:43:28 +0800 2008”)

Fredrik T. wrote:

Time.parse(“Fri May 23 16:43:28 +0800 2008”)

I do some coding in rails like these:
datetime = “”
msisdn = “”[0]), ‘r’) do |mbox|
RMail::Mailbox.parse_mbox(mbox) do |raw|
count += 1
print “Mail #{count}\n”
message =

msisdn = message.header['From']
datetime = message.header['Date']
print "From: " + message.header['From'] + "\n"
print "Date: " + message.header['Date'] + "\n"

datetime = message.header[‘Date’] will read the data as Fri May 23
16:43:28 +0800 2008 while mysql doesn’t match with these format.

So how do i format it in rails to match with mysql. Thanks


You may try with:

mysql_datetime = datetime.strftime(“%Y-%d-%m %H:%M:%S”)

Its a ruby (not rails) method from:

the rails method:


this will output any DateTime for use with SQL