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.$formatted_date = sprintf "%.2d.%2d.%2d", $mon+1, $mday, $year%100;
For the other issue, just convert your day,month,year into a number of days since a fixed date, e.g.:
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.=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);
In reply to Re: Calculating between times
by ysth
in thread Calculating between times
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |