Another thing you could try is $var = sprintf "%04d-%02d-%02d", $year,
$month, $day ;

-----Original Message-----
From: Adam Frielink [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, March 20, 2002 11:12 AM
To: Craig Sharp; [EMAIL PROTECTED]
Subject: RE: [Perl-unix-users] Finding start and end date for lastmonth




> -----Original Message-----
> From: Craig Sharp [mailto:[EMAIL PROTECTED]]
> Sent: Wednesday, March 20, 2002 12:45 PM
> The problem is that I need to assign the result to a variable and
> still maintain 2 characters for month and day.  This info must be
> sent to a database that only understands the format yyyy-mm-dd.
>
> If I dont print with printf using %04d-%02d-%02d, I get only
> single characters.

Not sure if you were looking for a response or not...

There is probably a better way to do this, but I will write what I simply
use...

$day_of_month = '9';
$day_of_month = '0' . $day_of_month if ($day_of_month < 10);
print $day_of_month;

The $day_of_month retains the scalar value expected.

Is there something wrong with the sprintf function?  You can use it to store
scalar values that have special formatting just like you would use the
printf.

Adam


_______________________________________________
Perl-Unix-Users mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
_______________________________________________
Perl-Unix-Users mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to