The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Pls help : file stamp issue on HP UX Servers siddaonline UNIX for Dummies Questions & Answers 2 07-04-2007 12:14 PM
how do i put a time stamp in a file name jhamm Shell Programming and Scripting 5 01-29-2007 10:00 AM
greping with time stamp arunkumar_mca Shell Programming and Scripting 1 07-28-2006 05:20 AM
capturing the time stamp pavan_test UNIX for Dummies Questions & Answers 4 07-18-2006 02:35 PM
How to MV without changing Time Stamp redlotus72 UNIX for Dummies Questions & Answers 3 07-15-2005 07:16 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 03-30-2009
supaLucas supaLucas is offline
Registered User
  
 

Join Date: Aug 2003
Location: Auckland
Posts: 3
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 (permalink)  
Old 03-30-2009
KevinADC KevinADC is offline Forum Advisor  
Registered User
  
 

Join Date: Jan 2008
Posts: 731
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 (permalink)  
Old 03-30-2009
supaLucas supaLucas is offline
Registered User
  
 

Join Date: Aug 2003
Location: Auckland
Posts: 3
Quote:
Originally Posted by KevinADC View Post
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 (permalink)  
Old 03-31-2009
supaLucas supaLucas is offline
Registered User
  
 

Join Date: Aug 2003
Location: Auckland
Posts: 3
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
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 06:19 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0