There is <%= distance_of_time_in_words(Time.now, @a_time) %> before xzy.<BR /> <!-- ^ this gives 2279 days --> 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 -- Posted via http://www.ruby-forum.com/.
Any ideas anyone? :) Kris Leech wrote:> There is <%= distance_of_time_in_words(Time.now, @a_time) %> before > xzy.<BR /> > <!-- ^ this gives 2279 days --> > > 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-- Posted via http://www.ruby-forum.com/.
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 -- Posted via http://www.ruby-forum.com/.
Maybe Matching Threads
- distance_of_time_in_words shows {{count}} days instead of showing actual days
- distance_of_time_in_words hardcoded strings should be separated for easier localization
- DateHelpers .. don' display.. ?
- Converting Date string to Time Object
- Testing helper/view methods from script/console