# Calling save changes a date field in my model instance to 2000

**URL:** <https://www.ruby-forum.com/t/calling-save-changes-a-date-field-in-my-model-instance-to-2000/184791>\
**Category:** Rails\
**Created:** [March 8, 2010, 6:55pm UTC](https://www.ruby-forum.com/t/calling-save-changes-a-date-field-in-my-model-instance-to-2000/184791 "2010-03-08T18:55:03Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![prichard](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/90db22/32.png) [@prichard](https://www.ruby-forum.com/u/prichard)\
**Post date:** [March 8, 2010, 6:55pm UTC](https://www.ruby-forum.com/t/calling-save-changes-a-date-field-in-my-model-instance-to-2000/184791/1 "2010-03-08T18:55:03Z")

</div>

Hi,

I’m having a problem with dates (laugh if you must :).

$ rails --version  
Rails 2.3.5  
$ ruby --version  
ruby 1.8.7 (2010-01-10 patchlevel 249) [x86\_64-linux]

I have a bunch of data in a text file that I’d like to place in my  
DB but am ending up with odd results when I save the data.

Here’s my model:

```
class CreateWaits < ActiveRecord::Migration
  def self.up
    create_table :waits do |t|
      t.string :location
      t.integer :reg_wait_min
      t.integer :lic_wait_min
      t.time :collection_time #This is the troublesome one

      t.timestamps
    end
  end

```

Here’s an interaction from the console. I make a new Wait and give it  
a collection\_time of Time.now. The resulting objects has a  
collection\_time that looks right, March, 2010. At this point I call  
save and then search for the newly inserted data. It comes back with a  
collection\_time in 2000. Any ideas what’s going on? I’m new to rails  
so any advice will be greatly appreciated.

> > w = Wait.new(:location =\> “Arl”,  
> > :reg\_wait\_min =\> 13,  
> > :lic\_wait\_min =\> 223,  
> > :collection\_time =\> Time.now())

=\> #\<Wait id: nil, location: “Arl”,  
reg\_wait\_min: 13, lic\_wait\_min: 223,  
collection\_time: “2010-03-08 09:20:40”, #HERE  
created\_at: nil, updated\_at: nil\>

> > w.save  
> > =\> true
> 
> > Wait.find(:all, :conditions =\> [“location = ‘Arl’”])  
> > =\> [#\<Wait id: 2983, location: “Arl”, reg\_wait\_min: 13,  
> > lic\_wait\_min: 223,  
> > collection\_time: “2000-01-01 09:20:40”, ## HUH?  
> > created\_at: “2010-03-08 14:20:55”, updated\_at: “2010-03-08  
> > 14:20:55”\>]

At this point w has also been updated to have the 2000 date.

```
thanks much for your help,
Paul
```

---

<div class="post-metadata">

**Author:** ![prichard](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/90db22/32.png) [@prichard](https://www.ruby-forum.com/u/prichard)\
**Post date:** [March 8, 2010, 7:43pm UTC](https://www.ruby-forum.com/t/calling-save-changes-a-date-field-in-my-model-instance-to-2000/184791/2 "2010-03-08T19:43:03Z")

</div>

On Mar 8, 2:47 pm, Paul R. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> DB but am ending up with odd results when I save the data.

it’s because you’ve asked for a time column (which means that only the  
time of day component is saved, the date is ignored). If you want date  
& time make your column be a datetime

Fred

---

<div class="post-metadata">

**Author:** ![prichard](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/90db22/32.png) [@prichard](https://www.ruby-forum.com/u/prichard)\
**Post date:** [March 8, 2010, 9:11pm UTC](https://www.ruby-forum.com/t/calling-save-changes-a-date-field-in-my-model-instance-to-2000/184791/3 "2010-03-08T21:11:26Z")

</div>

Frederick C. writes:

> On Mar 8, 2:47 pm, Paul R. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:
> 
> > Hi,

> > I have a bunch of data in a text file that I’d like to place in my  
> > DB but am ending up with odd results when I save the data.
> > 
> > Here’s my model:
> > 
> > ```
> > class CreateWaits < ActiveRecord::Migration
> > def self.up
> > create_table :waits do |t|
> > t.string :location
> > t.integer :reg_wait_min
> > t.integer :lic_wait_min
> > t.time :collection_time #This is the troublesome one
> > 
> > ```
> 
> it’s because you’ve asked for a time column (which means that only  
> the  
> time of day component is saved, the date is ignored). If you want  
> date  
> & time make your column be a datetime

Ah ha. That makes sense.

Thanks much,  
Paul
