Created
October 6, 2009 21:04
-
-
Save bps/203413 to your computer and use it in GitHub Desktop.
I often want to see a delta between two dates.
This file contains hidden or 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
#!/usr/bin/env ruby | |
require 'date' | |
raise 'Give two parseable arguments' unless ARGV.length == 2 | |
d1 = DateTime.parse(ARGV[0]) | |
d2 = DateTime.parse(ARGV[1]) | |
if d1 < d2 | |
d1, d2 = d2, d1 | |
end | |
hours,minutes,seconds,frac = Date.day_fraction_to_time(d1 - d2) | |
puts "The difference is #{hours / 24} day#{hours / 24 == 1 ? '' : 's'}, #{hours % 24} hour#{hours % 24 == 1 ? '' : 's'}, and #{minutes} minute#{minutes == 1 ? '' : 's'}." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment