Created
August 4, 2011 15:39
-
-
Save ream88/1125469 to your computer and use it in GitHub Desktop.
Difference between two dates
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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