Below is the code I'm using to calculate the number of months that have elapsed since a certain time (when our database was originally built). The following code currently works. My question is: I've fudged the months as being equal to "30" so the $elapsed_mons calculation will be correct (as of today anyways).

Other than using Date::Calc (which we don't have loaded and I'd like to avoid asking the dba's to load modules if possible - don't ask - politics) and Date::Manip which I hear is *really* *really* *really* impressive in it's flexibility but far beyond what I need (sledgehammer vs. toothpick?)... any ideas on how to better (more accurately) count the number of months since 6/30/99?

P.S.: $elapsed_mons returns "56" which is correct (as of today). Thanks for any advice/insight you can provide.

#!/usr/local/bin/perl5_8 use strict; use warnings; use Time::Local; #snipped stuff #Calculate elapsed months since today my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime; my $mo = $mon + 1; my $dy = $mday; my $yr = $year + 1900; #yep, extra steps but makes it clearer to me... my $now_date = "$yr/$mo/$dy"; my($ny, $nm, $nd) = $now_date =~ m<^(\d+)/(\d+)/(\d+)$>; my $ntime = timelocal(0, 0, 12, $nd, $nm-1, $ny); my $then_date = "1999/06/30"; # rpts will never go back beyond this d +ate my($ty, $tm, $td) = $then_date =~ m<^(\d+)/(\d+)/(\d+)$>; my $ttime = timelocal(0, 0, 12, $td, $tm-1, $ty); my $elapsed_mons = int(($ntime - $ttime)/( 60 * 60 * 24 * 30)); #use $elapsed_mons to generate drop down list of available report mont +hs #snipped stuff

Lori


In reply to Time::Local - calculate months elapsed by Lori713

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.