Change date-format in Ruby? I am using Rails and trying to import a logfile. The date-format that the log has is yyyymmdd;hhmmss:
20121216;233550

My MySQL server uses this to for its insert statements:
 MM/DD/YYYY HH:MM:SS 

How can I convert this string-format to the date-format?

require 'date'
DateTime.strptime('20121216;233550', '%Y%m%d;%H%M%S').strftime('%m/%d/%Y %H:%M:%S')

No magic, really.

Assuming that format remains fixed and contains no errors, you can create a Time object with:
d="20121216;233550"
Time.mktime(d[0..3], d[4..5],d[6..7],d[9..10],d[11.12],d[13..14])


If you're using Rails (which loads ActiveSupport), that format appears parseable using Time#parse:
Time.parse(source_dt).strftime('%m/%d/%Y %H:%M:%S')