Using
DateTime and
DateTime::Format::Duration:
#!/usr/bin/perl
use strict;
use warnings;
use DateTime;
use DateTime::Format::Duration;
my @dt;
for (qw( 30.01.08 05.03.08 )) {
local @_ = split /\./;
push @dt,
DateTime->new(
year => $_[2] + 2000,
month => $_[1],
day => $_[0],
time_zone => "Europe/Paris"
);
}
my $dur = $dt[1]->subtract_datetime( $dt[0] );
$dur->is_negative and
warn $dt[1]->dmy . 'is older than ' . $dt[0]->dmy . "\n";
# Choose the pattern to feet your needs
my $dtfd =
DateTime::Format::Duration->new( pattern => '%V weeks, %e days' );
my $formated_dtd = $dtfd->format_duration($dur);
print <<QUOTE;
Difference in weeks and days,
between @{[$dt[1]->dmy]} and @{[$dt[0]->dmy]}: $formated_dtd.
QUOTE
Date::Simple parses date strings and creates numerically comparable objects...
# Difference in days between two dates:
$diff = date('2001-08-27') - date('1977-10-05');