# Trying to insert a date

**URL:** <https://www.ruby-forum.com/t/trying-to-insert-a-date/147064>\
**Category:** Rails\
**Created:** [August 28, 2008, 7:54am UTC](https://www.ruby-forum.com/t/trying-to-insert-a-date/147064 "2008-08-28T07:54:37Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![dacbo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/b9e5f3/32.png) [@dacbo](https://www.ruby-forum.com/u/dacbo)\
**Post date:** [August 28, 2008, 7:54am UTC](https://www.ruby-forum.com/t/trying-to-insert-a-date/147064/1 "2008-08-28T07:54:37Z")

</div>

I’m a Ruby on Rails and MySQL newbie, trying to get started with the  
[lynda.com](http://lynda.com) training, so excuse my ignorance. Using Ruby 1.8.6, Rails  
1.1.6, and mysql 14.12 Distrib 5.051b for Win32 on a Vista machine (not  
using the current version of rails as the [lynda.com](http://lynda.com) training was using  
1.1.6 and using the newest version, some of the examples weren’t working  
(scafolding for example).

I’m just starting to learn how to work with databases. I have a mysql  
database up and running with an albums table, and have the following  
code in my controller:

def create  
@album = Album.new  
@album.title = ‘Aftermath’  
@album.artist = ‘The Rolling Stones’  
@album.genre = ‘Rock’  
@album.release\_date = ‘1966-01-01 12:00:00’  
render(:action =\> ‘show\_album’)  
end

I have had no problem reading from the database through other code, but  
when I do this, and then look at the variables (in my render),  
album.release\_date shows up as null. If I change the input date to a  
Time.now(), it works fine. (Before I had an @album.save and was getting  
an error that the release\_date was null (and can’t be as defined in the  
db).

Is there a reason why I can’t insert the release\_date of the album?

Thanks for the help, and again, forgive me if this should be obvious to  
me.

Swizzle

---

<div class="post-metadata">

**Author:** ![dacbo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/b9e5f3/32.png) [@dacbo](https://www.ruby-forum.com/u/dacbo)\
**Post date:** [August 28, 2008, 10:39am UTC](https://www.ruby-forum.com/t/trying-to-insert-a-date/147064/2 "2008-08-28T10:39:28Z")

</div>

On 28 Aug 2008, at 06:54, Chris Bedo wrote:

> I have had no problem reading from the database through other code,  
> but  
> when I do this, and then look at the variables (in my render),  
> album.release\_date shows up as null. If I change the input date to a  
> Time.now(), it works fine. (Before I had an @album.save and was  
> getting  
> an error that the release\_date was null (and can’t be as defined in  
> the  
> db).

On some platforms Ruby’s time object can’t deal with dates \< 1970. Is  
this a factor here ?  
Newer versions of rails cope with this (by using a DateTime object  
when approproate) but 1.1.6 may well not.

Another point of interest is that

> **[Rails 1.2.3: Compatible with Ruby 1.8.6 (and other fixes)](https://rubyonrails.org/2007/3/14/rails-1-2-3-compatible-with-ruby-1-8-6-and-other-fixes)**
>
> While Rails Edge continues to move forward at a rapid clip, we’ve still had the time to make sure that Rails 1.2.x stays in the game. This release irons out the few wrinkles there was between Ruby 1.8.6 and Rails 1.2.2. So now you can enjoy the...

says that rails 1.2.3 added compatibility with ruby 1.8.6 which  
rather implies that older versions (such as 1.1.6) might exhibit some  
quirks.

Fred

---

<div class="post-metadata">

**Author:** ![dacbo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/b9e5f3/32.png) [@dacbo](https://www.ruby-forum.com/u/dacbo)\
**Post date:** [August 28, 2008, 2:05pm UTC](https://www.ruby-forum.com/t/trying-to-insert-a-date/147064/3 "2008-08-28T14:05:40Z")

</div>

Frederick C. wrote:

> On 28 Aug 2008, at 06:54, Chris Bedo wrote:
> 
> > I have had no problem reading from the database through other code,  
> > but  
> > when I do this, and then look at the variables (in my render),  
> > album.release\_date shows up as null. If I change the input date to a  
> > Time.now(), it works fine. (Before I had an @album.save and was  
> > getting  
> > an error that the release\_date was null (and can’t be as defined in  
> > the  
> > db).
> 
> On some platforms Ruby’s time object can’t deal with dates \< 1970. Is  
> this a factor here ?  
> Newer versions of rails cope with this (by using a DateTime object  
> when approproate) but 1.1.6 may well not.
> 
> Another point of interest is that  
> [Ruby on Rails — Rails 1.2.3: Compatible with Ruby 1.8.6 (and other fixes)](http://weblog.rubyonrails.org/2007/3/14/rails-1-2-3-compatible-with-ruby-1-8-6-and-other-fixes)  
> says that rails 1.2.3 added compatibility with ruby 1.8.6 which  
> rather implies that older versions (such as 1.1.6) might exhibit some  
> quirks.
> 
> Fred

Since I am only copying what the [lynda.com](http://lynda.com) training video is doing (and  
he is inserting dates before 1970, I don’t believe that your first point  
is an issue, but if I can’t figure anything else out, I’ll have to  
assume that it could be a Rails compatibility issue with Ruby 1.8.6. I  
guess I’ll have to convert Rails to the newer version to try it out.

---

<div class="post-metadata">

**Author:** ![dacbo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/b9e5f3/32.png) [@dacbo](https://www.ruby-forum.com/u/dacbo)\
**Post date:** [August 28, 2008, 2:10pm UTC](https://www.ruby-forum.com/t/trying-to-insert-a-date/147064/4 "2008-08-28T14:10:46Z")

</div>

Chris Bedo wrote:

> Frederick C. wrote:
> 
> > On 28 Aug 2008, at 06:54, Chris Bedo wrote:
> > 
> > > I have had no problem reading from the database through other code,  
> > > but  
> > > when I do this, and then look at the variables (in my render),  
> > > album.release\_date shows up as null. If I change the input date to a  
> > > Time.now(), it works fine. (Before I had an @album.save and was  
> > > getting  
> > > an error that the release\_date was null (and can’t be as defined in  
> > > the  
> > > db).
> > 
> > On some platforms Ruby’s time object can’t deal with dates \< 1970. Is  
> > this a factor here ?  
> > Newer versions of rails cope with this (by using a DateTime object  
> > when approproate) but 1.1.6 may well not.
> > 
> > Another point of interest is that  
> > [Ruby on Rails — Rails 1.2.3: Compatible with Ruby 1.8.6 (and other fixes)](http://weblog.rubyonrails.org/2007/3/14/rails-1-2-3-compatible-with-ruby-1-8-6-and-other-fixes)  
> > says that rails 1.2.3 added compatibility with ruby 1.8.6 which  
> > rather implies that older versions (such as 1.1.6) might exhibit some  
> > quirks.
> > 
> > Fred
> 
> Since I am only copying what the [lynda.com](http://lynda.com) training video is doing (and  
> he is inserting dates before 1970, I don’t believe that your first point  
> is an issue, but if I can’t figure anything else out, I’ll have to  
> assume that it could be a Rails compatibility issue with Ruby 1.8.6. I  
> guess I’ll have to convert Rails to the newer version to try it out.

Whoops! I hadn’t had my morning coffee yet when I read Fred’s reply to  
my problem stating that some “platforms” might have pre-1970 issues.  
The [lynda.com](http://lynda.com) training video was run on a Mac-OS, while I’m running  
Vista. I tried changing the date to 1971, and everything worked fine.

Thanks for your help Fred.

Chris
