I am getting dates in a YYMMDD format. I need to find out if they are more than X days in the past. I want to install the Date::Calc module but it requires an ANSI C compiler. The boss says I can use anything that I can build with straight perl or nmake.exe (Windows systems), but cannot install an ANSI C compiler. Since we don't currently use it, he doesn't want it on production servers.

Are there other modules that would allow this? Here's a snippet of what I tried, but it didn't work:

use Time::Local; use constant MAX_AGE => 20; # Other code here sub older_than_MAX_AGE { my $date = _convert_date( $_[0] ); # convert yymmdd t +o epoch seconds my $max_epoch_seconds = MAX_AGE * 60 * 60 * 24; # MAX_AGE should b +e days. This converts it to seconds. my ( $day, $month, $year ) = (localtime)[3..5]; $year += 1900; my $today = timelocal( 0,0,0, $day, $month, $year ); my $cutoff_date = $today - $max_epoch_seconds; return $date < $cutoff_date ? 1 : 0 ; } sub _convert_date { # This takes a date in YYMMDD format and converts it to epoch seco +nds (assumes 12:00:00 midnight) my $date = shift; my ( $year, $month, $day ) = ( $date =~ /(\d\d)(\d\d)(\d\d)/ ); $year += 2000; timelocal( 0,0,0,$day,$month,$year ); }
When I pass "older_than_MAX_AGE" the date of 010329, I get the following data:

$cutoff_date '986281200'
$date '988527600'
$max_epoch_seconds 1728000
$_[0] '010329'
$today '988009200'

As you can see, it says that the date that I am passing in is *newer* than today: 988527600 > 988009200, even though today is 010423 and the date passed in is 010329. Can anyone see what I'm doing wrong?

Thanks, J. Atzger


In reply to How Many Days in the Past? 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.