# Formatted date down-counter - help!

**URL:** <https://www.ruby-forum.com/t/formatted-date-down-counter-help/60177>\
**Category:** Rails\
**Created:** [May 10, 2006, 10:10pm UTC](https://www.ruby-forum.com/t/formatted-date-down-counter-help/60177 "2006-05-10T22:10:04Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![rhrhrh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/7ab992/32.png) [@rhrhrh](https://www.ruby-forum.com/u/rhrhrh)\
**Post date:** [May 10, 2006, 10:10pm UTC](https://www.ruby-forum.com/t/formatted-date-down-counter-help/60177/1 "2006-05-10T22:10:04Z")

</div>

I’d like to have a count down to a certain date, but display it in  
words, such as “123 days away” or something. I’m aware of the function  
“distance\_of\_time\_in\_words\_to\_now()”, which will display “about 6 hours”  
or “12 days” or something like that, but how can I get it to reverse?  
Pass it a date for future reference, then it will error or be negative,  
right?

Any thoughts? Thanks…

---

<div class="post-metadata">

**Author:** ![rhrhrh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/7ab992/32.png) [@rhrhrh](https://www.ruby-forum.com/u/rhrhrh)\
**Post date:** [May 10, 2006, 11:59pm UTC](https://www.ruby-forum.com/t/formatted-date-down-counter-help/60177/2 "2006-05-10T23:59:04Z")

</div>

rh wrote:

> I’d like to have a count down to a certain date, but display it in  
> words, such as “123 days away” or something. I’m aware of the function  
> “distance\_of\_time\_in\_words\_to\_now()”, which will display “about 6 hours”  
> or “12 days” or something like that, but how can I get it to reverse?  
> Pass it a date for future reference, then it will error or be negative,  
> right?
> 
> Any thoughts? Thanks…

You want distance\_of\_time\_in\_words  
[http://api.rubyonrails.com/classes/ActionView/Helpers/DateHelper.html#M000466](http://api.rubyonrails.com/classes/ActionView/Helpers/DateHelper.html#M000466)

@time\_to\_event = distance\_of\_time\_in\_words(Time.now, 123.days.from\_now)  
@time\_to\_event #=\> ‘123 days’

---

<div class="post-metadata">

**Author:** ![rhrhrh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/7ab992/32.png) [@rhrhrh](https://www.ruby-forum.com/u/rhrhrh)\
**Post date:** [May 12, 2006, 4:15pm UTC](https://www.ruby-forum.com/t/formatted-date-down-counter-help/60177/3 "2006-05-12T16:15:14Z")

</div>

Alex W. wrote:

> rh wrote:
> 
> > I’d like to have a count down to a certain date, but display it in  
> > words, such as “123 days away” or something. I’m aware of the function  
> > “distance\_of\_time\_in\_words\_to\_now()”, which will display “about 6 hours”  
> > or “12 days” or something like that, but how can I get it to reverse?  
> > Pass it a date for future reference, then it will error or be negative,  
> > right?
> > 
> > Any thoughts? Thanks…
> 
> You want distance\_of\_time\_in\_words  
> [Peak Obsession](http://api.rubyonrails.com/classes/ActionView/Helpers/DateHelper.html#M000466)
> 
> @time\_to\_event = distance\_of\_time\_in\_words(Time.now, 123.days.from\_now)  
> @time\_to\_event #=\> ‘123 days’

Thanks, but won’t that always display ‘123 days’ (which was probably  
just to show how it works)? How can I pass a date format for about a  
year ahead of time?

Essentially:

@time\_to\_event = distance\_of\_time\_in\_words(Time.now, ‘Sat May 12  
05:00:00 Easter Standard Time 2006’)  
@time\_to\_event #=\> ‘365 days’

Then tomorrow, when you visit the site, it will say “364 days” then “363  
days” etc…

I think I just need the format - can I pass the MySQL datetime format?

Thanks!

---

<div class="post-metadata">

**Author:** ![rhrhrh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/7ab992/32.png) [@rhrhrh](https://www.ruby-forum.com/u/rhrhrh)\
**Post date:** [May 12, 2006, 4:19pm UTC](https://www.ruby-forum.com/t/formatted-date-down-counter-help/60177/4 "2006-05-12T16:19:55Z")

</div>

Nevermind. I had a typo. Thanks a lot!
