Skip to content

Instantly share code, notes, and snippets.

@ream88
Created August 4, 2011 15:39
Show Gist options
  • Save ream88/1125469 to your computer and use it in GitHub Desktop.
Save ream88/1125469 to your computer and use it in GitHub Desktop.
Difference between two dates
require 'rubygems'
require 'active_support/all'
time = ("2011-08-12 09:00:00").to_time
def diff(time)
delta = time - Time.now
%w[days hours minutes].collect do |step|
seconds = 1.send(step)
(delta / seconds).to_i.tap do
delta %= seconds
end
end
end
puts diff(time).inspect
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment