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

DateTime.parse(@email_date_time)

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.

Thanks.

Wawa

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

Emmie Wawa wrote:

Fredrik Thuresson wrote:

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

I do some coding in rails like these:
datetime = ""
msisdn = ""
File.open(Pathname.new(ARGV[0]), 'r') do |mbox|
  RMail::Mailbox.parse_mbox(mbox) do |raw|
    count += 1
    print "Mail #{count}\n"
    message = RMail::Parser.read(raw)

    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

Wawa

You may try with:

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

Its a ruby (not rails) method from: http://www.ruby-doc.org/core/classes/DateTime.html

the rails method:

date.to_s(:db)

this will output any DateTime for use with SQL