# The ruby way : DateTime calculations?

**URL:** <https://rubytalk.org/t/the-ruby-way-datetime-calculations/22667>\
**Category:** ruby-talk\
**Created:** [21 November 2005 22:48 UTC](https://rubytalk.org/t/the-ruby-way-datetime-calculations/22667 "2005-11-21T22:48:39Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Peter\_Fitzgibbons](https://avatars.discourse-cdn.com/v4/letter/p/e56c9b/32.png) [@Peter\_Fitzgibbons](https://rubytalk.org/u/Peter_Fitzgibbons)\
**Post date:** [21 November 2005 22:48 UTC](https://rubytalk.org/t/the-ruby-way-datetime-calculations/22667/1 "2005-11-21T22:48:39Z")

</div>

Is there an existent lib or such that gives me some date/time calculations ?

Time.now - 2.minutes for instance ?

Thanks,

> **···**
>
> --  
> Peter Fitzgibbons

---

<div class="post-metadata">

**Author:** ![Kirk\_Haines](https://avatars.discourse-cdn.com/v4/letter/k/c6cbf5/32.png) [@Kirk\_Haines](https://rubytalk.org/u/Kirk_Haines)\
**Post date:** [21 November 2005 23:08 UTC](https://rubytalk.org/t/the-ruby-way-datetime-calculations/22667/2 "2005-11-21T23:08:05Z")

</div>

Time.now - 2 \* 60

or

(some people would argue that this is the best approach)

Minute = 60  
Hour = Minute \* 60  
Day = Hour \* 24  
Time.now - 2 \* Minute

or

The ActiveSupport library for Rails has those sorts of methods defined.

or

I think Facets might have these, too.

or

Roll your own. They are easy to write.

Kirk Haines

> **···**
>
> On Monday 21 November 2005 3:48 pm, Peter Fitzgibbons wrote:
> 
> > Is there an existent lib or such that gives me some date/time calculations  
> > ?
> > 
> > Time.now - 2.minutes for instance ?

---

<div class="post-metadata">

**Author:** ![Ryan\_Leavengood](https://avatars.discourse-cdn.com/v4/letter/r/a587f6/32.png) [@Ryan\_Leavengood](https://rubytalk.org/u/Ryan_Leavengood)\
**Post date:** [21 November 2005 23:11 UTC](https://rubytalk.org/t/the-ruby-way-datetime-calculations/22667/3 "2005-11-21T23:11:55Z")

</div>

ActiveSupport, which is part of Rails, has this stuff. Take a look:

[http://api.rubyonrails.com/classes/ActiveSupport/CoreExtensions/Numeric/Time.html#M000234](http://api.rubyonrails.com/classes/ActiveSupport/CoreExtensions/Numeric/Time.html#M000234)

Ryan

> **···**
>
> On 11/21/05, Peter Fitzgibbons \<peter.fitzgibbons@gmail.com\> wrote:
> 
> > Is there an existent lib or such that gives me some date/time calculations ?
> > 
> > Time.now - 2.minutes for instance ?
