Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

number to date conversion

by sathya83aa (Acolyte)
on Jun 11, 2013 at 12:50 UTC ( #1038246=perlquestion: print w/replies, xml ) Need Help??

sathya83aa has asked for the wisdom of the Perl Monks concerning the following question:

Hi all..

I have a variable like MMDDYY. I would like to convert it into MM/DD/YY format.

Also I have a variable like 1234567890. I would like to convert it amount format with decimal values. ie 12,345,678.90

Please help me with this.

Thanks,

Sathya V.

Replies are listed 'Best First'.
Re: number to date conversion
by Anonymous Monk on Jun 11, 2013 at 13:02 UTC
Re: number to date conversion
by hippo (Chancellor) on Jun 11, 2013 at 13:30 UTC
    I have a variable like MMDDYY. I would like to convert it into MM/DD/YY format.
    join('/',$i=~/../g);

    which assumes $i is your variable.

Re: number to date conversion
by thezip (Vicar) on Jun 11, 2013 at 21:21 UTC

    Yet another WTDI:


    #!/perl/bin/perl use strict; use warnings; my $YYMMDD = '130510'; my @D = unpack('(A2)*', $YYMMDD); my $date = join('/', @D); print $date, "\n";

    What can be asserted without proof can be dismissed without proof. - Christopher Hitchens, 1949-2011
Re: number to date conversion
by jnyman (Acolyte) on Jun 11, 2013 at 13:34 UTC
    Suggestion:
    use 5.014; my $str = "123456"; say join '/' => $str =~ /../g; my $val = "213450"; my ( $whole, $dec ) = $val =~ /(.*?)(..?)$/; $dec = "0$dec" if length $dec == 1; $whole =~ s/(.{1,3}?)(?=(...)+$)/$1,/g; $whole //= 0; say "$whole.$dec";
      Thanks for your reply jnyman..I have the perl version v5.8.8 only, so unable to run your command. Can you please help me with someother suggestions?

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1038246]
Approved by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (2)
As of 2020-07-05 20:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?