Perl, time stamp issue. 60th minutes

Hi Guys,

Could you tell me how you can get the time stamp for 60th minutes?

Currently, we name our file using time stamp upto minutes and then add seconds at the end starting from 01.

And when the seconds reaches 60 we simply add 1 to the time stamp and reset the seconds to 00.

But the problem occurs when the minute hits 60.

For example, file name starts from

20090330225900.csv then goes to

20090330225959.csv.

Then instead of going to

20090330230000.csv it goes to

20090330226000.csv.

Following is the code,

  $seconds_count = 1;
  $date_r = `date +%Y%m%d%H%M`;
  $date_r = substr($date_r,0,-1);

  foreach $blahblah{

    if (length($seconds_count) == 1){
      $seconds_count = "0" . $seconds_count;
    }

    # Build up the filename
    $filename = "                  .
                $date_r                   .
                $seconds_count            .
                ".csv";

    $seconds_count++;

    if ($seconds_count > 59){
      $date_r = $date_r + 1;
      $seconds_count = 0;
    }

Do you recon the following would work?

    if ($seconds_count > 59){
      $date_r = `date +%Y%m%d%H%M`+ 1;
      $seconds_count = 0;
    }

And what should happen if the file name is:

20090331245959.csv

That will roll the day and month over as well as the HHMMSS. Is that what you want?

Besides being plenty of date modules available, there is the core Time::Local module and POSIX, you don't have to use the shells date command.

Hi Kevin,

Yes it should roll the day and month as well just as normal date does.

Could you kindly give an example how I can do this?

Cheers

Sweet.

$date_r = `date -d "+ 1 min" +%Y%m%d%H%M`;

was the answer.