activeperl@listserv.ActiveState.com
[Top] [All Lists]

RE: More time calculations

Subject: RE: More time calculations
From: "Wagner, David --- Senior Programmer Analyst --- WGO"
Date: Mon, 7 Mar 2005 14:00:58 -0800
activeperl-bounces@xxxxxxxxxxxxxxxxxxxxxxxx wrote:
> Hi all,
> 
> I keep having issues trying to calculate dates. Basically what I want
> to do is to go to the beginning of the previous month. So, I thought
> I could deduct the seconds that make up as many days as today is plus
> the seconds that make up as many days as the last month has. So I
> ended up with:    
> 
> $timevalue-=((($thisday - 4) * 24 * 60 * 60) + ($month_days * 24 * 60
> * 60)); 
        Then from you you have provided, then I will make an assumption that 
you have the month, day and year. So you could do:

        my $MyPriorMonth = $MyCurrMonth - 1;
        my $MyPriorYear  = $MyCurryear;

        if ( $MyPriorMonth < 1 ) {
                $MyPriorMonth = 12;
                $MyPriorYear--;
       }
      my $MyPrior1stMonth = timelocal(0, 0, 0, 1, $MyPriorMonth-1, 
$MyPriorYear);
        # 1st 0 - seconds
        # 2nd 0 - minutes
`       # 3rd 0 - hours
        # 4th   - day of month ( 1 )
        # 5th   - Month ( must subtract one since 0 thru 11 are used for month 
calculations
        # 6th   - year  ( seems like timelocal is able to handle 98 or 2005 or 
105 like it should, though I may be wrong)

        Also need to add:
        use Time::Local;

        Not that much code and once you get it going, should not run into 
problems.

Wags ;)
> 
> However, I do not know why I hit it by 4 days off. Could someone let
> me know if my logic was just wrong, if there's something I'm not
> aware of or if there is a better way to do it?  
> 
> Regards,
> 
> Javier Moreno
> 
> _______________________________________________
> ActivePerl mailing list
> ActivePerl@xxxxxxxxxxxxxxxxxxxxxxxx
> To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs



*******************************************************
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.
*******************************************************


_______________________________________________
ActivePerl mailing list
ActivePerl@xxxxxxxxxxxxxxxxxxxxxxxx
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

<Prev in Thread] Current Thread [Next in Thread>