Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Module for converting number to month name in perl

Tags:

perl

My XML date input is : 2012-12-21 i.e. YYYY-MM-DD format. I want to convert month number into month name. i.e. 2012-Dec-21 Can anyone suggest which perl module is useful & how to use it with an example since I am very new to perl.

like image 892
Singham Avatar asked Jun 05 '13 10:06

Singham


1 Answers

Use core perl's Time::Piece:

#!/usr/bin/perl

use 5.10;
use strict;
use warnings;

use Time::Piece;

my $date = '2012-12-21';
# strftime format - http://www.unix.com/man-page/FreeBSD/3/strftime/
my $t = Time::Piece->strptime($date, '%Y-%m-%d');
say $t->month;                # Dec
say $t->strftime('%Y-%b-%d'); # 2012-Dec-21
like image 79
Xaerxess Avatar answered Oct 13 '22 01:10

Xaerxess