How do you use Ruby CSV converters? -



How do you use Ruby CSV converters? -

suppose have next file:

textfield,datetimefield,numfield foo,2008-07-01 17:50:55.004688,1 bar,2008-07-02 17:50:55.004688,2

the ruby code read .csv like:

#!/usr/bin/env ruby require 'csv' csv = csv($stdin, :headers => true, :converters => :all) csv.each |row| print "#{row}" the_date = row['datetimefield'].to_date end

that code gives error message:

./foo2.rb:8:in `block in <main>': undefined method `to_date' "2008-07-01 17:50:55.004688":string (nomethoderror)

what gives?

i've read the docs, don't it.

edit: yes, parse fields individually. point of question want larn how utilize documented converters feature.

your date times don't match csv::datetimematcher regexp csv uses decide whether should effort date time conversion. looks of it's doing because of fractional seconds you've got.

you either overwrite constant or write own converter (datetime.parse seems happy strings)

ruby csv

Comments

Popular posts from this blog

delphi - blogger via idHTTP : error 400 bad request -

c++ - compiler errors when initializing EXPECT_CALL with function which has program_options::variables_map as parameter -

How do I check if an insert was successful with MySQLdb in Python? -