Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to convert apache log time to activerecord :datetime

I'd like to save apache logs to MySQL via ActiveRecord. In the apache log, the default time string is like:

[13/Aug/2008:00:50:49 -0700]

How can I convert it to a ActiveRecord :datetime type? Thanks!

like image 337
ohho Avatar asked Dec 23 '22 00:12

ohho


1 Answers

apache_time = "[13/Aug/2008:00:50:49 -0700]"
d = DateTime.strptime( apache_time, "[%d/%b/%Y:%H:%M:%S %Z]")

The format string is documented here: http://ruby-doc.org/core/classes/Time.src/M000298.html

like image 129
steenslag Avatar answered Jan 23 '23 20:01

steenslag