For the leading zero problem, use sprintf:
$formatted_date = sprintf "%.2d.%2d.%2d", $mon+1, $mday, $year%100;
Update: everything from this point on, except the very last sentence, is intended mainly for humor value. For practical advice, go straight to the end.

For the other issue, just convert your day,month,year into a number of days since a fixed date, e.g.:

=head2 greg2rd $rd = greg2rd( $year, $month, $day ); Convert gregorian year,month,day to days on or after Jan 1, 1 CE (Gregorian). Normalization is performed (e.g. month of 28 means April two years after given year) for month < 1 or > 12 or day < 1 or > last day of month. =cut sub greg2rd { use integer; my ( $y, $m, $d ) = @_; my $adj; # make month in range 3..14 (treat Jan & Feb as months 13..14 of p +rev year) if ( $m <= 2 ) { $y -= ( $adj = ( 14 - $m ) / 12 ); $m += 12 * $adj; } elsif ( $m > 14 ) { $y += ( $adj = ( $m - 3 ) / 12 ); $m -= 12 * $adj; } # make year positive (oh, for a use integer 'sane_div'!) if ( $y < 0 ) { $d -= 146097 * ( $adj = ( 399 - $y ) / 400 ); $y += 400 * $adj; } # add: day of month, days of previous 0-11 month period that began + w/March, # days of previous 0-399 year period that began w/March of a 400-m +ultiple # year, days of any 400-year periods before that, and -306 days to + adjust # from Mar 1, year 0-relative to Jan 1, year 1-relative (whew) $d += ( $m * 367 - 1094 ) / 12 + $y % 100 * 1461 / 4 + ( $y / 100 * 36524 + $y / 400 ) - 306; } # is date $formatted_then more than $autodelete days ago? ($mon,$mday,$year) = (localtime)[4,3,5]; $now = greg2rd($year+1900, $mon+1, $day); ($mon,$mday,$year) = split /\./, $formatted_then; $then = greg2rd($year+1900, $mon, $day); delete if ($now - $then > $autodelete);
Or instead of going to all of that bother, learn one of the fine modules that handle dates for you: DateTime,Date::Calc,Date::Manip.

In reply to Re: Calculating between times by ysth
in thread Calculating between times by Anonymous Monk

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.