I want to change a string returned from the following format to a date that shows how many months days since the last order was placed from a customer, I have the following code on the page to get the result –
<% @lastorder = Order.select("DateCreated").where("customer_id == ?", customer.id).order("Datecreated desc").find(:all, :limit => 1) %>
but this then returns the following format –
[#<Order DateCreated: "2013-01-09 00:00:00">]
There is probably a better way to do this but I am unaware of it at the moment.
I would rewrite your query like that :
If you want to display the time distance in words, you should use the rails helper :
distance_of_time_in_words_to_now(@last_order)Info: Just discover than
distance_of_time_in_words_to_nowis an alias oftime_ago_in_words, shorter.