# Distance\_of\_time\_in\_words and Time classes

**URL:** <https://www.ruby-forum.com/t/distance-of-time-in-words-and-time-classes/90102>\
**Category:** Rails\
**Created:** [March 29, 2006, 5:59pm UTC](https://www.ruby-forum.com/t/distance-of-time-in-words-and-time-classes/90102 "2006-03-29T17:59:18Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![krisleech](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/59ef9b/32.png) [@krisleech](https://www.ruby-forum.com/u/krisleech)\
**Post date:** [March 29, 2006, 5:59pm UTC](https://www.ruby-forum.com/t/distance-of-time-in-words-and-time-classes/90102/1 "2006-03-29T17:59:18Z")

</div>

There is \<%= distance\_of\_time\_in\_words(Time.now, @a\_time) %\> before  
xzy.

This does not work because when @a\_time is stored, even though it is a  
Time field and the class is Time, it includes a date. The Date isn’t  
even that days date its the year 2000, hence the 2279 days ago.

So how do I set the date part of @a\_time (a Time class) to today’s date  
so that distance\_of\_time\_in\_words works as expected?

Cheers K.

AFM

---

<div class="post-metadata">

**Author:** ![krisleech](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/59ef9b/32.png) [@krisleech](https://www.ruby-forum.com/u/krisleech)\
**Post date:** [April 5, 2006, 4:00pm UTC](https://www.ruby-forum.com/t/distance-of-time-in-words-and-time-classes/90102/2 "2006-04-05T16:00:37Z")

</div>

Any ideas anyone? 🙂

Kris L. wrote:

> There is \<%= distance\_of\_time\_in\_words(Time.now, @a\_time) %\> before  
> xzy.
> 
> This does not work because when @a\_time is stored, even though it is a  
> Time field and the class is Time, it includes a date. The Date isn’t  
> even that days date its the year 2000, hence the 2279 days ago.
> 
> So how do I set the date part of @a\_time (a Time class) to today’s date  
> so that distance\_of\_time\_in\_words works as expected?
> 
> Cheers K.
> 
> AFM

---

<div class="post-metadata">

**Author:** ![krisleech](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/59ef9b/32.png) [@krisleech](https://www.ruby-forum.com/u/krisleech)\
**Post date:** [April 5, 2006, 4:35pm UTC](https://www.ruby-forum.com/t/distance-of-time-in-words-and-time-classes/90102/3 "2006-04-05T16:35:39Z")

</div>

kris wrote:

> Any ideas anyone? 🙂

Is Time immutable ?

You may have to remove multiple days worth of seconds to get the sub-day  
part.

difference\_in\_time\_in\_words( (Time.now - @a\_time) mod (60 \* 60 \* 12) )

Alan
