Created
December 22, 2014 23:03
-
-
Save losomo/dea65735d5e6f763dc7c to your computer and use it in GitHub Desktop.
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
#!/usr/bin/perl | |
use strict; | |
use warnings; | |
use DateTime; | |
use POSIX::strptime; | |
my $date1a = parse_date('03-SEP-10'); | |
my $date1b = parse_date('01-JAN-13'); | |
my $days1d = $date1a->delta_days($date1b)->days; | |
my $days1dd = $date1a->delta_days($date1b)->delta_days; | |
print "$days1dd != $days1d\n"; #prints 851 != 4 | |
my $date2a = parse_date('16-OCT-01'); | |
my $date2b = parse_date('01-JAN-13'); | |
my $days2d = $date2a->delta_days($date2b)->days; | |
my $days2dd = $date2a->delta_days($date2b)->delta_days; | |
print "$days2dd != $days2d\n"; # prints 4095 != 0 | |
sub parse_date { | |
my ($mday, $mon, $year) = (POSIX::strptime($_[0], '%d-%b-%y'))[3,4,5]; | |
return DateTime->new( | |
year => $year, | |
month => $mon + 1, | |
day => $mday, | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment