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');

In reply to Re: How do i compare dates with format dd.mm.yy by poolpi
in thread How do i compare dates with format dd.mm.yy by cab

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.