> -----Original Message-----
> From: Gregg O'Donnell [mailto:[EMAIL PROTECTED]]
> Sent: Tuesday, August 13, 2002 9:14 AM
> To: [EMAIL PROTECTED]
> Subject: Formatting date, time
> 
> I'm looking for the simplest way to use the date and time in 
> the format of MMDDYYHHmm (no spaces), which is used later in 
> the program.

Use the POSIX module's strftime() (see below)

> 
> Here's what I've come up with; comments or suggestions are 
> appreciated.
> 
> #Insert Date and Time
> my $month = $mon00   #Two digit month
> my $day = $mday00   #Two digit day in month
> my $year = $year    #Two digit year
> my $hour = $hour00   #Two digit: Hour
> my $min = $min00   #Two digit: Minutes

Why are you assigning one set of variables to another
set of variables? Also, these statements lack semicolons.
Where did the values in $mon00, $mday00, etc. come from?

> #Combine date and time above into MMDDYYHHmm format
> my @log_date = qw($month$day$year$hour$min)

Nope, that's not what qw// is for. See perldoc perlop
for more details.

To answer the original question:

1) Use localtime() and sprintf(), which is a bit messy:

   my (undef,$min,$hour,$mday,$mon,$year) = localtime;
   my $date = sprintf '%02d%02d%02d%02d%02d', $m + 1, $d,
       $y % 100, $hour, $min;

or, 2) Use the POSIX module's strftime(), which is simpler:

   use POSIX 'strftime';
   my $date = strftime('%02m%02d%02y%02H%02M', localtime);

perldoc -f localtime
perldoc -f sprintf
perldoc POSIX

HTH

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to