# Date Functions

**URL:** <https://discuss.rubyonrails.org/t/date-functions/10805>\
**Category:** rubyonrails-talk\
**Created:** [March 26, 2007, 4:29pm UTC](https://discuss.rubyonrails.org/t/date-functions/10805 "2007-03-26T16:29:35Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Bill\_Walton](https://avatars.discourse-cdn.com/v4/letter/b/f07891/32.png) [@Bill\_Walton](https://discuss.rubyonrails.org/u/Bill_Walton)\
**Post date:** [March 26, 2007, 4:29pm UTC](https://discuss.rubyonrails.org/t/date-functions/10805/1 "2007-03-26T16:29:35Z")

</div>

Hi Mick,

Mick wrote:

> I would like to be able to do a date comparison to return the number of days left until a date (stored in my database) is reached. I can't seem to find a ruby function that will do such an operation

In this case, you're looking for Rails helper modules, not Ruby methods. If you haven't already, check out ActiveSupport::CoreExtensions::Time::Calculations for more of them.

> and regardless of this, other ruby functions throw errors when I try to apply them to this date, e.g.
> 
> the\_event.start\_on.next\_week()
> 
> returns this error:
> 
> undefined method `next\_week' for "2007-03-28 18:30:00":String

next\_week works on a Time object and the\_event.start\_on is apparently a String object. If you're intentionally storing it as a String, you could use the to\_time conversion before applying the next\_week method.

C:\InstantRails-1.5\rails\_apps\sandbox\>ruby script\console Loading development environment.

> > event=Time.now

=\> Mon Mar 26 11:26:25 -0500 2007

> > event\_string = event.to\_s

=\> "Mon Mar 26 11:26:25 -0500 2007"

> > event\_string.to\_time.next\_week

=\> Mon Apr 02 00:00:00 UTC 2007

> >

hth, Bill
