Forum: Ruby on Rails formatted date down-counter - help!

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
rh (Guest)
on 2006-05-11 00:10
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...
Alex W. (Guest)
on 2006-05-11 01:59
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/Help...

@time_to_event = distance_of_time_in_words(Time.now, 123.days.from_now)
@time_to_event #=> '123 days'
rh (Guest)
on 2006-05-12 18:15
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
> http://api.rubyonrails.com/classes/ActionView/Help...
>
> @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!
rh (Guest)
on 2006-05-12 18:19
Nevermind.  I had a typo.  Thanks a lot!
This topic is locked and can not be replied to.