Perl, time stamp issue. 60th minutes


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Perl, time stamp issue. 60th minutes
# 1  
Old 03-30-2009
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,

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?

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


Last edited by Yogesh Sawant; 03-31-2009 at 03:24 AM.. Reason: added code tags
# 2  
Old 03-30-2009
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.
# 3  
Old 03-30-2009
Quote:
Originally Posted by KevinADC
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
# 4  
Old 03-31-2009
Sweet~ got it sorted

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

was the answer.

Last edited by Yogesh Sawant; 03-31-2009 at 03:22 AM.. Reason: added code tags
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Check file creation Time minutes and if file older then 5 minutes execute some stuff

Hello all, Info: System RedHat 7.5 I need to create a script that based on the creation time, if the file is older then 5 minutes then execute some stuff, if not exit. I thought to get the creation time and minutes like this. CreationTime=$(stat -c %y /tmp/test.log | awk -F" " '{ print... (3 Replies)
Discussion started by: charli1
3 Replies

2. Shell Programming and Scripting

Perl:Script to append date and time stamp

Help with Perl script : I have a web.xml file with a line <display-name>some_text_here</display-name> Need to append the current date and time stamp to the string and save the XML file Something like <display-name>some_text_here._01_23_2014_03_56_33</display-name> -->Finally want... (5 Replies)
Discussion started by: gaurav99
5 Replies

3. Solaris

System time and Cron time stamp not matching

On Solaris 10 server the system date won't match with the timestamp on files created by a cron jobs, Please help here is what i get when i check for system date infodba-ie10ux014:/tcpdv1_ie10/tcadmin/bin\n\r-> date Tue Apr 24 15:27:43 GMT 2012at same time i executed a cron job, and checked... (4 Replies)
Discussion started by: karghum
4 Replies

4. Shell Programming and Scripting

Unable to create logfile with local time stamp using perl

Hello All, Morning, I am facing problem with my code while creating a log with name as current time stamp using perl. Here is the code. #!/usr/bin/perl my $time=localtime; my ($day,$month,$date,$tm,$year)=split(/ /,$time); my $stamp=$year."_".$month."_".$date; my... (4 Replies)
Discussion started by: krsnadasa
4 Replies

5. Shell Programming and Scripting

How to get time duration between two human readable time stamp in Unix?

Here is two time I have: Jul 12 16:02:01 Jul 13 01:02:01 and how can I do a simple match to get difference between two time which is 09:00:00 Thanks in advance. (3 Replies)
Discussion started by: ford99
3 Replies

6. Shell Programming and Scripting

regarding time stamp

hi everyone i am facing a strange problem here suppose content of my file is a=1,2,3 b=2,3,4 c=4,5,6 time= now the problem is i want to add value in front of time variable and the value should be i format only "HHMMSS" so it should be like this a=1,2,3 b=2,3,4 c=4,5,6... (3 Replies)
Discussion started by: aishsimplesweet
3 Replies

7. UNIX for Dummies Questions & Answers

How to get the next time stamp in perl?

Hi, I have to find the next time stamp in perl. Here is the code. @time = loaltime(time); print "\n Present time: $time:$time:$time \n"; For example if the time is: "12:55:02" after some process the time becomes 1:00:00. How do i check when it becomes 00:00 i.e from "12:55:02... (0 Replies)
Discussion started by: vanitham
0 Replies

8. Shell Programming and Scripting

Perl - Extract 12 hour time, convert to 24 and subtract 15 minutes?

OK, I am by no means a programmer... I have been given the task to do some automation scripts. I have got most of it working from snippets I have found on the Web. One requirement has me stumped. The initial timing file created by the user is a comma delimited in the following format.... (4 Replies)
Discussion started by: autotuner
4 Replies

9. Shell Programming and Scripting

time stamp perl script error out of range 1..31

Hi, while running the perl script i am getting this error message , Day '' out of range 1..31 at rsty.sh line 44 what do iam missing in the script, any suggestion #!/usr/bin/perl use Time::Local; my $wday = $ARGV; my $month = $ARGV; # convert the month shortname into 0-11 number if... (4 Replies)
Discussion started by: saha
4 Replies

10. UNIX for Dummies Questions & Answers

How to MV without changing Time Stamp

Hi, I need to move the set of files, and it should be same time stamp as previous. How to do this? (3 Replies)
Discussion started by: redlotus72
3 Replies
Login or Register to Ask a Question