Datetime format

These code is to read the email i save in the text file that i have
retrieved from gmail.

msisdn = “”
datetime = “”
date = “”
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']

When i do
date = DateTime.parse(datetime)
the result is 2008-06-05T08:45:58+00:00

But i only want the format to be 2008-06-05 08:45:58 because only these
match the mysql datetime format. Is there other way of do the parsing?
Thanks

Wawa

Emmie W. wrote:

But i only want the format to be 2008-06-05 08:45:58 because only these
match the mysql datetime format. Is there other way of do the parsing?
Thanks

Wawa

You can output the datetime in any format you desire using the strftime
method. Off the top of my head, something like this may do the trick:

date.strftime(’%Y-%m-%d %H:%M:%S)

for usage in db you can do:

date.to_s(:db)

this will output any DateTime for use with SQL