Date format

C

cc96ai

I want to change the date format in perl script

input: "2005-11-01"
output:November 1, 2005

thanks
 
G

Gunnar Hjalmarsson

cc96ai said:
I want to change the date format in perl script

input: "2005-11-01"
output:November 1, 2005

The POSIX::strftime() function may be helpful.
 
C

Carl

cc96ai said:
I want to change the date format in perl script

input: "2005-11-01"
output:November 1, 2005

thanks

You might be interested in the Date::Simple module:

--example--
$ cat test.pl
#!/usr/bin/perl

use strict;
use warnings;

use Date::Simple qw/date/;

my $d = date('2005-11-01');
print $d->format('%B %d, %Y'), "\n";

__END__

$ ./test.pl
November 01, 2005
$
--end example--

See:
http://search.cpan.org/dist/Date-Simple/lib/Date/Simple.pm

Hope that helps,
Carl.
 
G

Gunnar Hjalmarsson

Greg said:
use Date::parse qw/ strptime /;
use POSIX qw/ strftime /;

# output:November 1, 2005
my $date = "2005-11-01";

my(undef,undef,undef,$day,$month,$year) = strptime $date;
print strftime("%B %e, %Y\n", 0, 0, 0, $day, $month, $year);

Or shorter:

print strftime("%B %d, %Y\n", 0, 0, 0, (strptime $date)[3..5]);

(%d is a more portable specifier than %e. The latter does not work on my
Windows XP box.)
 
C

cartercc

I want to change the date format in perl script

input: "2005-11-01"
output:November 1, 2005

thanks

If you want to roll your own, do this:

%months = (
1 => "January",
2 => "February",
3 => "March",
etc )

@input = split /-/, $input;
printf "%s $d, $d", $months{$input[1]}, $input[2], $input[0];

CC
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,767
Messages
2,569,572
Members
45,045
Latest member
DRCM

Latest Threads

Top