> > "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 > 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. >
Excellent questions. 'time' returns the number of seconds from a specific point in time, in most cases Jan 1 1970, 00:00:00. So for instance when I started this sentence, I had the following # of seconds: 1085762425 >From this I can subtract 60*60 to get 1 hour ago from the point when the time was read as it relates to that initial starting point (also known as the epoch, Jan 1 1970). Then using 'localtime' I can translate that time back into a readable format. Because localtime is just translating a set point in time, and all of my calculations were done using seconds, I don't have to worry about boundaries, such as hour, day, month, or years. There are a lot of caveats about working with times, but the same is going to hold whether you are using something like 'add_delta' or the built-ins. Make sense? I am reluctant to just give code since it doesn't reinforce the learning, but if you are still stuck post again, we will get you sorted. http://danconia.org -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>