[Rails] Re: formatted date down-counter - help!

rh
Fri, 12 May 2006 14:15:29 -0000

Alex Wayne 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/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!