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

Time problems - Help!

Expand Messages
  • John Drabinowicz
    Hi Gang, I m trying to do something that should be relatively simple but can t get there from here. I m trying to subtract a then date/time from a now
    Message 1 of 2 , Jan 27, 2003
      Hi Gang,

      I'm trying to do something that should be relatively simple but can't get
      there from here.
      I'm trying to subtract a then date/time from a now date/time and print the
      difference.

      # the example below prints out -- "Program ran for 0"

      Please what am I missing?

      example:
      my $start_time = 0;
      my $stop_time = 0;
      my $diff_time = 0;

      $start_time = localtime;

      [BLOCK] # does something that takes < 1 min. to > 1 day

      $stop_time = localtime;

      $diff_time = $stop_time - $start_time;

      Print "Program ran for: $diff_time\n";

      1;

      Thanks,
      John D.


      [Non-text portions of this message have been removed]
    • Jeff 'japhy' Pinyan
      ... Then use time(), not localtime(). ... In scalar context, localtime() returns a string representing the current day and time, not a number of seconds. --
      Message 2 of 2 , Jan 27, 2003
        On Jan 27, John Drabinowicz said:

        >I'm trying to subtract a then date/time from a now date/time and print the
        >difference.

        Then use time(), not localtime().

        >$start_time = localtime;

        In scalar context, localtime() returns a string representing the current
        day and time, not a number of seconds.

        --
        Jeff "japhy" Pinyan japhy@... http://www.pobox.com/~japhy/
        RPI Acacia brother #734 http://www.perlmonks.org/ http://www.cpan.org/
        <stu> what does y/// stand for? <tenderpuss> why, yansliterate of course.
        [ I'm looking for programming work. If you like my work, let me know. ]
      Your message has been successfully submitted and would be delivered to recipients shortly.