RE: Date in perl



Thanks Luke now I understand how to do it thanks



-----Original Message-----
From: Bakken, Luke [mailto:Luke.Bakken@xxxxxxxxxxxxx]
Sent: Saturday, August 27, 2005 10:22 AM
To: Gomez, Juan; beginners@xxxxxxxx
Subject: RE: Date in perl



Hi all


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?

---------------------------------------

I normally don't just give out answers. Next time I'm sure someone will
say "do your own homework....".

If you want to do this yourself, look at the following:

POSIX module (strftime function)
substr function.

Otherwise, look at the code below.





























use strict;
use POSIX;

my $date = 20050829;
my ($y, $m, $d) = (substr($date, 0, 4), substr($date, 4, 2),
substr($date, 6, 2));

print strftime("%a %d %Y", 0, 0, 0, $d, $m-1, $y-1900);

--
To unsubscribe, e-mail: beginners-unsubscribe@xxxxxxxx For additional
commands, e-mail: beginners-help@xxxxxxxx <http://learn.perl.org/>
<http://learn.perl.org/first-response>

.



Relevant Pages

  • Re: Could this be made shorter and cleaner?
    ... Chris, I have gone for John method of using the ... > is calling the POSIX strftime and putting it in a list, ... this is telling perl that the only function we want to import from the ... POSIX module is 'strftime'. ...
    (perl.beginners)
  • RE: Date in perl
    ... POSIX module (strftime function) ... use strict; ... Prev by Date: ...
    (perl.beginners)
  • Re: Small date question
    ... much easier to use strftime from the POSIX module. ... everywhere perl is. ... Unfortunately the Perl documentation for strftime ...
    (comp.lang.perl.misc)
  • Re: Easiest way to do this?
    ... perl had a ceiling function. ... Well, Perl has the ceil() that comes with the POSIX module, which comes ...
    (comp.lang.perl.misc)