# Importing data and Time.parse

**URL:** <https://www.ruby-forum.com/t/importing-data-and-time-parse/133938>\
**Category:** Rails\
**Created:** [April 5, 2008, 6:50am UTC](https://www.ruby-forum.com/t/importing-data-and-time-parse/133938 "2008-04-05T06:50:20Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![rashantha](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/b9bd4f/32.png) [@rashantha](https://www.ruby-forum.com/u/rashantha)\
**Post date:** [April 5, 2008, 6:50am UTC](https://www.ruby-forum.com/t/importing-data-and-time-parse/133938/1 "2008-04-05T06:50:20Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![rashantha](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/b9bd4f/32.png) [@rashantha](https://www.ruby-forum.com/u/rashantha)\
**Post date:** [April 5, 2008, 10:55pm UTC](https://www.ruby-forum.com/t/importing-data-and-time-parse/133938/2 "2008-04-05T22:55:58Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![rashantha](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/b9bd4f/32.png) [@rashantha](https://www.ruby-forum.com/u/rashantha)\
**Post date:** [April 6, 2008, 3:10am UTC](https://www.ruby-forum.com/t/importing-data-and-time-parse/133938/3 "2008-04-06T03:10:00Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![rashantha](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/b9bd4f/32.png) [@rashantha](https://www.ruby-forum.com/u/rashantha)\
**Post date:** [April 6, 2008, 1:12am UTC](https://www.ruby-forum.com/t/importing-data-and-time-parse/133938/4 "2008-04-06T01:12:28Z")

</div>

hello–

On Apr 5, 2008, at 1:54 PM, rashantha wrote:

> i am not going to try and run a loop and attempt to convert the data
> 
> > c.my\_date = Time.parse(row[6]) shows up as “2008-05-07” , the time is  
> > 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.

---

<div class="post-metadata">

**Author:** ![rashantha](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/b9bd4f/32.png) [@rashantha](https://www.ruby-forum.com/u/rashantha)\
**Post date:** [April 6, 2008, 3:38am UTC](https://www.ruby-forum.com/t/importing-data-and-time-parse/133938/5 "2008-04-06T03:38:40Z")

</div>

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](http://dizzy.co.uk/ruby_on_rails/cheatsheets/rails-migrations)
