For Programmers: Free Programming Magazines  


Home > Archive > PERL Beginners > November 2006 > Formatting Variables









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Formatting Variables
banker123

2006-11-02, 7:56 am

I use the code below to get the $dayOfMonth, the value of $dayOf MOnth
today is 2. I need to use this variable in the format of 02, can
someone help?

($second, $minute, $hour, $dayOfMonth, $month, $yearOffset, $dayOfW,
$dayOfYear, $daylightSavings) = localtime();

DJ Stunks

2006-11-02, 7:56 am


banker123 wrote:
> I use the code below to get the $dayOfMonth, the value of $dayOf MOnth
> today is 2. I need to use this variable in the format of 02, can
> someone help?
>
> ($second, $minute, $hour, $dayOfMonth, $month, $yearOffset, $dayOfW,
> $dayOfYear, $daylightSavings) = localtime();


sprintf

-jp

Kay

2006-11-02, 9:57 pm

you could use the following:

use strict;
my ($second, $minute, $hour, $dayOfMonth, $month, $yearOffset,
$dayOfW,
$dayOfYear, $daylightSavings) = localtime();
$dayOfMonth=sprintf("%02d", $dayOfMonth);

-Kay

On Nov 2, 9:07 am, "banker123" <bradbrock...@yahoo.com> wrote:
> I use the code below to get the $dayOfMonth, the value of $dayOf MOnth
> today is 2. I need to use this variable in the format of 02, can
> someone help?
>
> ($second, $minute, $hour, $dayOfMonth, $month, $yearOffset, $dayOfW,
> $dayOfYear, $daylightSavings) = localtime();


banker123

2006-11-02, 9:57 pm

> $dayOfMonth=sprintf("%02d", $dayOfMonth);

Got it thanks!

Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2009 codecomments.com