importing data and Time.parse

results from console and server are different.

i am importing a date as a string

"05/07/2008 10:00 AM"

c.my_date = Time.parse(row[6]) shows up as "2008-05-07" , the time is dropped

but when i test this in the controller it works

c.my_date = Time.parse("05/07/2008 10:00 AM") shows up correctly as a full date

i am assuming that this has something with the way the data is being saved while importing.

i can also inject the date in the model on the console and do a save with the correct results.

can anyone explain what is going on and how i can solve this.

there was no reply to this and further searching reveals frustration from others but not concrete pointers.

i would like to reiterate that it is not a db issue because when the values are injected to the model it appears correctly. this is from script/console.

i would greatly appreciate some help on this issue.

i am not going to try and run a loop and attempt to convert the data in the hopes that is an issue with csv, but from other posting i am anticipating further problems.

hello--

there was no reply to this and further searching reveals frustration from others but not concrete pointers.

i would like to reiterate that it is not a db issue because when the values are injected to the model it appears correctly. this is from script/console.

i would greatly appreciate some help on this issue.

i am not going to try and run a loop and attempt to convert the data in the hopes that is an issue with csv, but from other posting i am anticipating further problems.

results from console and server are different.

i am importing a date as a string

"05/07/2008 10:00 AM"

c.my_date = Time.parse(row[6]) shows up as "2008-05-07" , the time is dropped

but when i test this in the controller it works

c.my_date = Time.parse("05/07/2008 10:00 AM") shows up correctly as a full date

i am assuming that this has something with the way the data is being saved while importing.

i can also inject the date in the model on the console and do a save with the correct results.

can anyone explain what is going on and how i can solve this.

Here are some steps you can take to solve this:

In console, do:

p Time.parse("05/07/2008 10:00 AM").class

compare the results to:

p Time.parse(row[6]).class

If these are different, why are they different?

How about:

p Time.parse("05/07/2008 10:00 AM").to_s

versus:

p Time.parse(row[6]).to_s

If there aren't any clues there, then please give people on the list an idea what is in row[6] and what you observe in your controller.

ross i have tried comparing several issue in the console as well as in the controller.

Time.parse("05/07/2008 10:00 AM").class is a value of TIME

i am storing the information in DATE field.

row[6] is coming from CSV import. row[6] is correctly a value of string ie: "05/07/2008 10:00 AM" i have tried .to_s

i have also stored row[6] in a STRING variable and it saves the entire information.

i can then read the information in the console from DB, use Time.parse and inject it back into the DATE variable and all works well.

but i have yet to figure out why in the controller the time component is dropped and only the "05/07/2008" is saved in the format "2008-05-07" without the time.

SOLVED.

col needed to datetime thanks ross for making me look the 20th time at it.

http://dizzy.co.uk/ruby_on_rails/cheatsheets/rails-migrations