David Samuelsson (PAC) wrote:
> I have an nice script that lest me list stuff from a certian date in
> time. It based on: 
> 
> DD-MON-YY (say 01-jan-03) that will be from the first of january. I
> am trying to add more functionality to the script. I need a function
> where i get an variable $days say 90, then i must subtract 90 days
> from my value DD-MON-YY and it should give me the right date. I
> allready have the DD-MON-YY as diffrent variables. But if this is
> going to work i guess i have to make the script aware of how many
> days each month have dont i? or is there some easier way? And i cant
> use an module for this! I can only use an old perl v5.001 due to that
> is whats installed, usually with the package. Not many modules is
> included in the package.         
> 
> Any pointers appriciated.
> 
> //Dave

  If you can't load other modules, then you should with a little work using
timelocal, localtime and a hash, you should be able to do it:

Here is a simple script which allow syou to enter a date, number days back
and then print out the dates, etc.  It will give you a strting point. It may
need other test to verify that the data is indeed valid. I am asuming dates
are from 2000 and above. If not then other tests would need to be done to
get the right info:

use Time::Local;

my $MyInp ;
my $MyCurrDate ;
my $MyDateBack ;
my $MyDateBackPrt;

while ( 1 ) {
    printf "Please enter Date: ";
    chomp($MyInp = <STDIN>);
    last if ( $MyInp =~ /(qu|ex)/i );
    proc_mydate( $MyInp, $MyCurrDate );
    printf "How many days back: ";
    chomp($MyDateBack = <STDIN>);
    $MyDateBack = $MyCurrDate - ( 86400 * $MyDateBack);
    proc_getdate($MyDateBack, $MyDateBackPrt);
    printf "Curr Date: %-9s  %9d\nBack Date: %-9s  %9d\n", $MyInp,
$MyCurrDate,
                                                           $MyDateBackPrt,
$MyDateBack;;
 }

sub proc_mydate {
    my ( $MyDate, $MyEpochDate) = @_;
    my %MyMon = ( 'jan', 0, 'feb', 1, 'mar', 2, 'apr', 3, 'may', 4, 'jun',
5,
                  'jul', 6, 'aug', 7, 'sep', 8, 'oct', 9, 'nov', 10, 'dec',
11);

    my @MyWorka = split(/\s*-\s*/, $MyDate);
    $MyEpochDate = timelocal(0,0,12,$MyWorka[0], $MyMon{lc($MyWorka[1])},
(2000+$MyWorka[2]));
    $_[1] = $MyEpochDate;
 } # end of proc_mydate

sub proc_getdate {
    my ($MyDateBack, $MyDateBackPrt) = @_;
    my @MyMon = qw( jan feb mar apr may jun jul aug sep oct nov dec);
    my (@TimeInfo) = localtime($MyDateBack);
    $_[1] = sprintf "%-d\-%-s\-%-d", $TimeInfo[3], $MyMon[$TimeInfo[4]],
($TimeInfo[5] % 100);
 }  # end of get_time             

Wags ;)


**********************************************************
This message contains information that is confidential
and proprietary to FedEx Freight or its affiliates.
It is intended only for the recipient named and for
the express purpose(s) described therein.
Any other use is prohibited.
****************************************************************


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to