Re: Date in perl




On Sat, 27 Aug 2005, Gomez, Juan wrote:

>
> I have a problem need to work with date
>
> I have a input like these : 20050829 and I need to change it to
> something like this : Aug 29 2005
>
> but it still eludes me how to do that
>
> can anyone help me please?


Well the steps are;

1. Break it into three pieces 2005 08 29
2. Relate 08 to Aug
3. Reassemble in the order you want.

To break it up, use unpack

my ( $y, $m, $d ) = unpack( "A4 A2 A2", 20050809 );

To relate a number to a month, try an array

my @monthhs = qw(Jan Feb .... Dec);

or use a hash

my %months = (
1 => "Jan",
2 => "Feb",
etc
12 => "Dec");

and to print it the way you want, try

print "$d $month{$m} $y\n";


See how you go with that

.



Relevant Pages