# MySQL and loading dates for timestamp columns from CSV

**URL:** <https://www.ruby-forum.com/t/mysql-and-loading-dates-for-timestamp-columns-from-csv/144076>\
**Category:** Rails\
**Created:** [July 25, 2008, 6:45am UTC](https://www.ruby-forum.com/t/mysql-and-loading-dates-for-timestamp-columns-from-csv/144076 "2008-07-25T06:45:37Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![andy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/aeb1de/32.png) [@andy](https://www.ruby-forum.com/u/andy)\
**Post date:** [July 25, 2008, 6:45am UTC](https://www.ruby-forum.com/t/mysql-and-loading-dates-for-timestamp-columns-from-csv/144076/1 "2008-07-25T06:45:37Z")

</div>

Hello, using MySQL, FasterCSV and have a CSV dump of blog posts to be  
imported as production data, except the created\_at and updated\_at  
columns are always populated for me and not read from the CSV!

I tried renaming the columns, tried changing the type to import them  
as strings, this worked (as strings), but then when I changed the type  
to datetime, they NULL’d out (expected?).

This happens for all my models that use the timestamp columns. All  
tables were created from migrations using t.timestamps.

I tried messing with record\_timestamps as well to no avail. this must  
be a general problem, hoping it’s something simple. tia!

def import\_csv(file)  
name = File.basename(file, ‘.csv’)  
puts  
puts “truncating existing #{name} data…”  
ActiveRecord::Base.connection.execute(“truncate table  
#{name.pluralize.underscore}”)

puts “parsing #{name}.csv…”  
rows = FasterCSV.read(file, :quote\_char =\> ‘\’)  
column\_names = rows.shift

puts “importing #{rows.size} rows…”  
count = (eval “#{name}.import(column\_names, rows)”).num\_inserts

puts “successfully imported #{count} rows!”  
puts  
end

---

<div class="post-metadata">

**Author:** ![andy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/aeb1de/32.png) [@andy](https://www.ruby-forum.com/u/andy)\
**Post date:** [August 5, 2008, 5:56am UTC](https://www.ruby-forum.com/t/mysql-and-loading-dates-for-timestamp-columns-from-csv/144076/2 "2008-08-05T05:56:29Z")

</div>

I’m back on this issue and think it is because the ar-extensions  
“import” method will automatically set the created\_at and updated\_at  
columns. It would be nice if there was some option to not do that. I  
have an email to the creator out and am awaiting response. Listed as  
a feature of ar-extensions 0.7 here:  
[http://groups.google.com/group/ruby-talk-google/browse\_thread/thread/d1532df0a06ddb90](http://groups.google.com/group/ruby-talk-google/browse_thread/thread/d1532df0a06ddb90)
