Skip to content

Instantly share code, notes, and snippets.

@johnf
Created April 18, 2012 10:30
Show Gist options
  • Save johnf/2412698 to your computer and use it in GitHub Desktop.
Save johnf/2412698 to your computer and use it in GitHub Desktop.
#!/usr/bin/perl
use DateTime;
use Date::Parse;
my $e1 = str2time($ARGV[0]);
my $e2 = str2time($ARGV[1]);
$d1 = DateTime->from_epoch( epoch => $e1 )->set_time_zone('floating');;
$d2 = DateTime->from_epoch( epoch => $e2 )->set_time_zone('floating');;
my $months = ($d2 - $d1)->in_units('months');
print "Months $months\n";
# ./months_apart.pl 2012-04-01 2012-05-01
# Months 0
#
# ./months_apart.pl 2012-04-01 2012-05-02
# Months 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment