Loading ...
Sorry, an error occurred while loading the content.

Date Manipulation Code ..

Expand Messages
  • Oliver Manickum
    Hey Guys, Any one here have a snippet that adds and subtracts dates ?.. - Olly Oliver Manickum ____________________________ ePages Internet & Multimedia
    Message 1 of 4 , Sep 14 3:42 AM
    • 0 Attachment
      Hey Guys,
       
          Any one here have a snippet that adds and subtracts dates ?..
       
      - Olly

      Oliver Manickum
      ____________________________
      ePages Internet & Multimedia
      http://www.epages.net/
      Tel : +27 (0)31 2651281

       
    • Greg Webster
      ... The following will work. I ve given you the whole script, but it s small and should be easy to go through and rip out the code. Greg Your faithful
      Message 2 of 4 , Sep 14 7:31 AM
      • 0 Attachment
        On Thu, 14 Sep 2000, you wrote:
        > Any one here have a snippet that adds and subtracts dates ?..

        The following will work. I've given you the whole script, but it's small and
        should be easy to go through and rip out the code.

        Greg
        Your faithful moderator

        #!/usr/local/bin/perl
        ##############################################################
        # Access31 - access_log trimmer
        # Copyright (c)2000 - Greg Webster
        # see access31.conf to add an access_log to be trimmed
        ##############################################################

        $conffile = '/usr/local/scripts/access31/access31.conf';

        ##############################################################

        # List months in order
        @months = ('Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec');

        ##############################################################
        # Get all the present date stuff and the start date (based on conf
        # file)
        # PRESENT TIME #############################################
        sub presenttime
        {
        my $time = time;
        my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($time);
        $year = $year + 1900;
        $nullspace = '';
        if ($mday < 10)
        {
        $nullspace = '0';
        }
        $nowtime = $nullspace."$mday\/$months[$mon]\/$year";
        }
        # OLD TIME #################################################
        sub starttime
        {
        my $time = time;
        my $logdays = shift;
        $time = $time - ($logdays * 86400);
        my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($time);
        $year = $year + 1900;
        $nullspace = '';
        if ($mday < 10)
        {
        $nullspace = '0';
        }
        $startlogtime = $nullspace."$mday\/$months[$mon]\/$year";
        }
        ##############################################################

        ##############################################################
        # Trimlog - determine the applicable start date of the log file, write
        # lines that are within the timeframe allowed to a temporary file,
        # the copy that file in place when complete.
        sub trimlog
        {
        open(LOGFILE, $logpath) || die("Cannot open $logpath for reading");
        open(TEMPOUTLOG, ">/tmp/access31_templog") || die ("Cannot write to /tmp/access31_templog");
        &starttime($logdays);
        $containeddate = "";
        while (<LOGFILE>)
        {
        if ($_ =~ $startlogtime)
        {
        print TEMPOUTLOG "$_";
        $containeddate = "true";
        last;
        }
        }
        while (<LOGFILE>)
        {
        print TEMPOUTLOG "$_";
        }
        close TEMPOUTLOG;
        close LOGFILE;
        }

        ##############################################################
        # Get all the info from the access31 conf file, call the trimlog
        # subroutine based on that info
        sub do_conf
        {
        open(CONFFILE, $conffile) || die("Can't open $conffile for reading");
        while (<CONFFILE>)
        {
        $line = $_;
        unless($line =~ /^#/ || $line =~ /^[\s\t]*$/)
        {
        ($logpath,$logdays,$logowner,$loggroup) = split(/[\s\t]+/, $line);
        &trimlog;
        &put_trimmed_log; # Put trimmed log file in place listed in conf file
        }
        }
        close CONFFILE;
        }

        ##############################################################
        # Put new, trimmed log file in place, making sure ownership is preserved
        sub put_trimmed_log
        {
        if ($containeddate eq "true")
        {
        $devnull = `cp /tmp/access31_templog $logpath`;
        $devnull = `chown $logowner:$loggroup $logpath`;
        }
        unlink("/tmp/access31_templog");
        }



        --
        < >-< >< >-< >< >-< >< >-< >< >-< >< >-< >< >-< >< >-< >< >
        | | | GREG WEBSTER - greg@... | | | |
        <_>-<_><_>-<_><_>-<_><_>-<_><_>-<_><_>-<_><_>-<_><_>-<_><_>
      • Andrew Johnson
        ! Any one here have a snippet that adds and subtracts dates ?.. Check out the Date::Calc and/or Date::Manip modules. regards, andrew -- Andrew L. Johnson
        Message 3 of 4 , Sep 14 7:39 AM
        • 0 Attachment
          ! Any one here have a snippet that adds and subtracts dates ?..

          Check out the Date::Calc and/or Date::Manip modules.

          regards,
          andrew

          --
          Andrew L. Johnson http://members.home.net/andrew-johnson/
          In theory, there's no difference between
          theory and practice, but in practice there is!
        • Oliver Manickum
          ta Greg, muchos helpful ;O) - Olly ... From: Greg Webster [mailto:greg@gadgeteer.net] Sent: Thursday, September 14, 2000 4:31 PM To: perl-beginner@egroups.com
          Message 4 of 4 , Sep 14 1:46 PM
          • 0 Attachment
            RE: [PBML] Date Manipulation Code ..

            ta Greg,

                    muchos helpful ;O)

            - Olly

            -----Original Message-----
            From: Greg Webster [mailto:greg@...]
            Sent: Thursday, September 14, 2000 4:31 PM
            To: perl-beginner@egroups.com
            Subject: Re: [PBML] Date Manipulation Code ..


            -------------------------- eGroups Sponsor -------------------------~-~>
            Your family still won't know what you do.  At least they'll know where.
            The resources, brainpower & breadth of opportunities at Microsoft are
            unmatched. The only question is are you ready for that kind of impact?
            http://click.egroups.com/1/9223/15/_/12898/_/968942088/
            ---------------------------------------------------------------------_->

            On Thu, 14 Sep 2000, you wrote:
            >     Any one here have a snippet that adds and subtracts dates ?..

            The following will work. I've given you the whole script, but it's small and
            should be easy to go through and rip out the code.

            Greg
            Your faithful moderator

            #!/usr/local/bin/perl
            ##############################################################
            # Access31 - access_log trimmer
            # Copyright (c)2000 - Greg Webster
            # see access31.conf to add an access_log to be trimmed
            ##############################################################

            $conffile = '/usr/local/scripts/access31/access31.conf';

            ##############################################################

            # List months in order
            @months = ('Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec');

            ##############################################################
            # Get all the present date stuff and the start date (based on conf
            # file)
            #   PRESENT TIME   #############################################
            sub presenttime
             {
             my $time = time;
             my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($time);
             $year = $year + 1900;
             $nullspace = '';
             if ($mday < 10)
                     {
                     $nullspace = '0';
                     }
             $nowtime = $nullspace."$mday\/$months[$mon]\/$year";
             }
            #   OLD TIME   #################################################
            sub starttime
             {
             my $time = time;
             my $logdays = shift;
             $time = $time - ($logdays * 86400);
             my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($time);
             $year = $year + 1900;
             $nullspace = '';
             if ($mday < 10)
                     {
                     $nullspace = '0';
                     }
             $startlogtime = $nullspace."$mday\/$months[$mon]\/$year";
             }
            ##############################################################

            ##############################################################
            # Trimlog - determine the applicable start date of the log file, write
            # lines that are within the timeframe allowed to a temporary file,
            # the copy that file in place when complete.
            sub trimlog
             {
             open(LOGFILE, $logpath) || die("Cannot open $logpath for reading");
             open(TEMPOUTLOG, ">/tmp/access31_templog") || die ("Cannot write to /tmp/access31_templog");
             &starttime($logdays);
             $containeddate = "";
             while (<LOGFILE>)
                     {
                     if ($_ =~ $startlogtime)
                             {
                             print TEMPOUTLOG "$_";
                             $containeddate = "true";
                             last;
                             }
                     }
             while (<LOGFILE>)
                     {
                     print TEMPOUTLOG "$_";
                     }
             close TEMPOUTLOG;
             close LOGFILE;
             }

            ##############################################################
            # Get all the info from the access31 conf file, call the trimlog
            # subroutine based on that info
            sub do_conf
             {
             open(CONFFILE, $conffile) || die("Can't open $conffile for reading");
             while (<CONFFILE>)
                     {
                     $line = $_;
                     unless($line =~ /^#/ || $line =~ /^[\s\t]*$/)
                             {
                             ($logpath,$logdays,$logowner,$loggroup) = split(/[\s\t]+/, $line);
                             &trimlog;
                             &put_trimmed_log;       # Put trimmed log file in place listed in conf file
                             }
                     }
             close CONFFILE;
             }

            ##############################################################
            # Put new, trimmed log file in place, making sure ownership is preserved
            sub put_trimmed_log
             {
             if ($containeddate eq "true")
                     {
                     $devnull = `cp /tmp/access31_templog $logpath`;
                     $devnull = `chown $logowner:$loggroup $logpath`;
                     }
             unlink("/tmp/access31_templog");
             }



            --
            < >-< >< >-< >< >-< >< >-< >< >-< >< >-< >< >-< >< >-< >< >
             |   |  |  GREG WEBSTER - greg@...   |  |   |  |
            <_>-<_><_>-<_><_>-<_><_>-<_><_>-<_><_>-<_><_>-<_><_>-<_><_>






          Your message has been successfully submitted and would be delivered to recipients shortly.