date - how many days until

Given a date I need to find out how many days until that date. for example if I am given march 29 and today is march 27 how would I return 2 days?

I need to verify this in the controller and distance_of_time_in_words doesn't work

Given a date I need to find out how many days until that date. for example if I am given march 29 and today is march 27 how would I return 2 days?

x = 3.days.from_now

=> Sun Mar 30 20:55:40 -0700 2008

y = Time.now

=> Thu Mar 27 20:55:45 -0700 2008

(x - y) / 86400

=> 2.99994818523148

x = 3.days.from_now.to_date

=> #<Date: 4909111/2,0,2299161>

y = Time.now.to_date

=> #<Date: 4909105/2,0,2299161>

(x - y).to_i

=> 3

-philip

Philip Hallstrom wrote:

Given a date I need to find out how many days until that date. for example if I am given march 29 and today is march 27 how would I return 2 days?

How about: Date.tomorrow - Date.today

Or: Date.new(2008, 4, 1) - Date.today