> -----Original Message-----
> From: [EMAIL PROTECTED]
> [mailto:[EMAIL PROTECTED]]
> Sent: Thursday, February 07, 2002 7:02 AM
> To: [EMAIL PROTECTED]
> Subject: Date::Calc date returned format
> 
> 
> All,
>       using the following code under W2K Activestate v5.6.1 
> (629), I get the 
> date output as : 20 days ago, it was 20020118
> 
> I would like to drop the leading '20' in 2002 so it would 
> read: 20 days ago, it 
> was 020118. I know I could just rip it out but I would like 
> to know how to 
> return the date from the module in 2 digit year format.
> 
> Thanks in advance,
> Patrick
> 
>       **************************
> 
> use Date::Calc qw( :all );
> 
>   ($year, $month, $day) = Add_Delta_Days (Today, -20);
> 
> printf "20 days ago, it was %02d%02d%d\n", $year, $month, $day;

The format %02d treats $year as an integer and prints it in a field
*at least* 2 columns wide, with leading zeros if necessary. If the
number is larger than 99, more than two columns will be output.

You can convert 2002 to 2 by using the modulus operator:

   printf "20 days ago, it was %02d%02d%d\n", $year % 100, $month, $day;

An alternative is to treat $year as a string and take the two
rightmost characters:

   printf "20 days ago, it was %02d%02d%d\n", substr($year, -2), $month,
$day;

I would use the % operator myself.

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

Reply via email to