# Rails dates and times, 40.years.ago

**URL:** <https://www.ruby-forum.com/t/rails-dates-and-times-40-years-ago/75171>\
**Category:** Rails\
**Created:** [November 7, 2006, 11:18pm UTC](https://www.ruby-forum.com/t/rails-dates-and-times-40-years-ago/75171 "2006-11-07T23:18:38Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [November 7, 2006, 11:18pm UTC](https://www.ruby-forum.com/t/rails-dates-and-times-40-years-ago/75171/1 "2006-11-07T23:18:38Z")

</div>

Simple test case:  
require ‘rubygems’  
require ‘active\_support’  
puts 5.years.ago  
puts 40.years.ago

It seems to be an issue on windows, as the linux version of the test  
below works just fine, but windows will crash with an ArgumentError:  
time must be positive.

Does anyone have a solution/workaround so that I can create database  
queries that search for users older than 35 on my windows test box?

Thank you.

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [November 8, 2006, 1:19am UTC](https://www.ruby-forum.com/t/rails-dates-and-times-40-years-ago/75171/2 "2006-11-08T01:19:00Z")

</div>

removed\_email\_address@domain.invalid wrote:

> Does anyone have a solution/workaround so that I can create database  
> queries that search for users older than 35 on my windows test box?
> 
> Thank you.

The ‘ruby-units’ gem can handle datetime math like this and will  
automagically convert to a DateTime from a Time when necessary.

Using ruby-units, you would use

‘40 years’.ago

\_Kevin

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [September 29, 2008, 7:01am UTC](https://www.ruby-forum.com/t/rails-dates-and-times-40-years-ago/75171/3 "2008-09-29T07:01:33Z")

</div>

puts Time.year.now-40  
puts Time.year.now-80

it is another solution if u dont want upgrade your rails.

Y Reinhart AP  
[Teapoci.Blogspot.com](http://Teapoci.Blogspot.com)
