# Mysql date out of range

**URL:** <https://www.ruby-forum.com/t/mysql-date-out-of-range/168340>\
**Category:** Rails\
**Created:** [May 19, 2009, 7:14pm UTC](https://www.ruby-forum.com/t/mysql-date-out-of-range/168340 "2009-05-19T19:14:53Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![pink-ink](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/9dc877/32.png) [@pink-ink](https://www.ruby-forum.com/u/pink-ink)\
**Post date:** [May 19, 2009, 7:14pm UTC](https://www.ruby-forum.com/t/mysql-date-out-of-range/168340/1 "2009-05-19T19:14:53Z")

</div>

Hi ruby community,

I use ruby 1.8.6, rails 2.2.2 and mysql 5.045.

In my scaffold I use “t.date :birthday”.

When I want to save a birthday like 12.05.1970 I can save it. But when  
I try to save older birthdays like 12.05.1969 I get the error-message  
“time out of range”.

Remarkable is, when I try to save the date without ruby/rails directly  
in the mysl-database, there is no error-message, so it must be a kin of  
ruby/rails bug.

Do somebody know a solution?

Thanks in front for every proposal for solution:-)

Regs Hermann

---

<div class="post-metadata">

**Author:** ![pink-ink](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/9dc877/32.png) [@pink-ink](https://www.ruby-forum.com/u/pink-ink)\
**Post date:** [May 19, 2009, 7:58pm UTC](https://www.ruby-forum.com/t/mysql-date-out-of-range/168340/2 "2009-05-19T19:58:40Z")

</div>

On Tue, May 19, 2009 at 10:14 AM, Herman  
Müller[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> ruby/rails bug.  
> Can you print the entire error message and stack trace, if any?

I just tried this on the same setup and had no error.

–  
Hassan S. ------------------------ removed\_email\_address@domain.invalid

---

<div class="post-metadata">

**Author:** ![pink-ink](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/9dc877/32.png) [@pink-ink](https://www.ruby-forum.com/u/pink-ink)\
**Post date:** [May 19, 2009, 7:46pm UTC](https://www.ruby-forum.com/t/mysql-date-out-of-range/168340/3 "2009-05-19T19:46:17Z")

</div>

Dates can’t store earlier than I think 1970 something. Use time.

Blog: [http://random8.zenunit.com/](http://random8.zenunit.com/)  
Twitter: [http://twitter.com/random8r](http://twitter.com/random8r)  
Learn: [http://sensei.zenunit.com/](http://sensei.zenunit.com/)  
New video up now at [http://sensei.zenunit.com/](http://sensei.zenunit.com/) real fastcgi rails  
deploy process! Check it out now!

On 20/05/2009, at 3:14 AM, Herman M¨¹ller  
\<removed\_email\_address@domain.invalid

---

<div class="post-metadata">

**Author:** ![pink-ink](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/9dc877/32.png) [@pink-ink](https://www.ruby-forum.com/u/pink-ink)\
**Post date:** [May 19, 2009, 7:59pm UTC](https://www.ruby-forum.com/t/mysql-date-out-of-range/168340/4 "2009-05-19T19:59:16Z")

</div>

2009/5/19 Julian L. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> Dates can’t store earlier than I think 1970 something. Use time.

The MySQL Date doc for 5.0.x says:

The DATE type is used when you need only a date value, without a time  
part. MySQL retrieves and displays DATE values in ‘YYYY-MM-DD’ format.  
The supported range is ‘1000-01-01’ to ‘9999-12-31’.

## FYI,

Hassan S. ------------------------ removed\_email\_address@domain.invalid

---

<div class="post-metadata">

**Author:** ![pink-ink](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/9dc877/32.png) [@pink-ink](https://www.ruby-forum.com/u/pink-ink)\
**Post date:** [May 22, 2009, 10:30am UTC](https://www.ruby-forum.com/t/mysql-date-out-of-range/168340/5 "2009-05-22T10:30:25Z")

</div>

On May 22, 9:25 am, Herman Müller [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> ```
> else quote_without_date_cast(value, column)
> 
> ```
> 
> Do somebody knows a solution?

While the ruby Date class has an absolutely massive range, Time  
doesn’t, so the plugin shouldn’t really be converting a date instance  
into a instance of Time (at least not without checking if it is  
possible first)

Fred

---

<div class="post-metadata">

**Author:** ![pink-ink](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/9dc877/32.png) [@pink-ink](https://www.ruby-forum.com/u/pink-ink)\
**Post date:** [May 22, 2009, 10:25am UTC](https://www.ruby-forum.com/t/mysql-date-out-of-range/168340/6 "2009-05-22T10:25:57Z")

</div>

Thanks for all suggestions!

I made a little date experiment and the normal date range of ruby 1.8.6,  
rails 2.2.2 and mysql 5.045 is between 01.01.0001 and 01.01.3000 or  
greater.

The error message “argument out of range” appears only when I use the  
DHTMLCalendar plugin from

ruby script/plugin install  
[http://dhtml-calendar.googlecode.com/svn/trunk](http://dhtml-calendar.googlecode.com/svn/trunk)

The first two lines of the Application-Trace

vendor/plugins/svn/lib/extensions/active\_record.rb:61:in `local' vendor/plugins/svn/lib/extensions/active_record.rb:61:in `quote’

are pointing to a fault in the active\_record.rb of the  
DHTMLCalendar-plugin:

Line 61: when Date then “‘#{quoted\_date(Time.local(value.year,  
value.month, value.day, 0, 0, 0))}’”  
else quote\_without\_date\_cast(value, column)

Do somebody knows a solution?

Thanks in front.

Regs Hermann
