Anthony J Segelhorst wrote:
> "Wiggins d Anconia" <[EMAIL PROTECTED]> wrote on 05/28/2004
> 12:37:56 PM:
> 
>>> 
>>> I am trying to set up a script that will do the do a current time
>>> -1 routine. 
>>> 
>>> Examples:
>>> 
>>> Current Time:
>>> mmddyy:hhss
>>> 052804:1030
>>> 
>>> Output:
>>> 052804:0930
>>> 
>>> 
>>> Current Time:
>>> 052704:0015
>>> 
>>> Output:
>>> 052604:23:15
>>> 
>>> 
>>> I think the add_delta module is where I need to go, but I have
>>> never used modules before. 
>>> 
>> 
>> add_delta is probably a method/function in Date::Calc or Date::Manip
>> modules. But in this case is probably overkill.
>> 
>> You can use the built-in functions 'time' and 'localtime' to get the
>> desired effect. 
>> 
>> perldoc -f time
>> perldoc -f localtime
>> 
>> 'time' will return the current time, from which you can subtract
>> 60*60 (60 seconds in each of 60 minutes), which gives 1 hour ago.
>> You can then use localtime to retrieve the values for the specific
>> fields you need at the calculated time.  Alternatively you could use
>> POSIX::strftime for the formatting. 
>> 
>> perldoc POSIX
>> 
>> HTH,
>> 
>> http://danconia.org
> 
> If I understand what you are saying about subtract 60 seconds in each
> of 60 minutes, how will this be able to handle:
> 
>         1.  When it is 00:15, because if it is 00:15 I will actually
> want 23:15
        What they are saying is that you subtract using seconds from time:
                $My1Hour = time - ( 60 * 60);
                my @MyTime = localtime($My1Hour);
# These are the values returened by localtime;
#    0    1    2     3     4    5     6     7     8
#   ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
    $MyTime[4]++;
# need to add 1 to month since the months come back in 0 to 11 vs 1 thru 12.
   Now @MyTime  has the info in the format you want for getting one hour back.
If you want 2 digit year then $MyTime[5] % 100 will give you 04.

A start.

Wags ;)  ps When you do it this way, it will handle all the year ehds, month end, etc 
correctly for you.  The gotchas can be at the time of Day Light Savings if in US.


>         2.  I can not just subtract 1 from the date because 010104
> needs to really be 123104.
> 
> If this is not what you are suggesting, let me know.  You might be
> onto something.
> 
> 
> This is the part that is confusing me currently.  I am just trying to
> get logical understanding of what I want to do before I start writing
> the code.
> 


*******************************************************
This message conatains 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]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to