Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

How to change the language of Date value retrieved from XML file which was stored in number format using DateTime::Format::Excel module in Perl

by Kottur (Initiate)
on May 05, 2014 at 09:39 UTC ( [id://1085026]=perlquestion: print w/replies, xml ) Need Help??

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

The data which has been entered into excel file is stored as an XML file in one of my tools.

During the XML file storage process, the date value is stored in number format. For Ex: 11-May-2014 ==> 41770. I don't know how it is stored the date value in number format.

Now, I am trying to retrieve the date value which was stored in the XML file using "DateTime::Format::Excel" module. The code snippet is attached below,

Could anyone please tell me, how to change the language (English, French, German, etc.,) of the date value printed. But, i need the format should be "DD-Abbreviated Month Name-YYYY"

use DateTime::Format::Excel; use Date::Simple qw(d8); use XML::Simple; use String::Util("trim"); $RequiredValue = "%XML_FILE_ABSOLUTE_PATH%"; $XmlHandle = XMLin($RequiredValue, SuppressEmpty => 1); $temp = trim($XmlHandle -> {Date}); $DateVal = DateTime::Format::Excel -> parse_datetime($temp) -> ymd(); $DateVal =~ s/-//g; print (d8($DateVal)->format("%d-%b-%Y"));
  • Comment on How to change the language of Date value retrieved from XML file which was stored in number format using DateTime::Format::Excel module in Perl
  • Download Code

Replies are listed 'Best First'.
Re: How to change the language of Date value retrieved from XML file which was stored in number format using DateTime::Format::Excel module in Perl
by poj (Abbot) on May 05, 2014 at 09:53 UTC
    Try
    #!perl use strict; use Spreadsheet::ParseExcel::Utility qw(ExcelFmt); print ExcelFmt("dd-mmm-yyyy", 41770);
    poj
Re: How to change the language of Date value retrieved from XML file which was stored in number format using DateTime::Format::Excel module in Perl
by Anonymous Monk on May 05, 2014 at 11:24 UTC

    DateTime::Format::Excel's parse_datetime returns a regular DateTime object. To format one of those, use any of the DateTime::Format:: modules. Or, for somewhat less flexible formatting, use its ->strftime() method together with ->set_locale():

    use DateTime::Format::Excel; my $x=DateTime::Format::Excel->parse_datetime(41770); $x->set_locale("de_DE"); print $x->strftime('%d-%b-%Y'); # "11-Mai-2014"

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others chanting in the Monastery: (4)
As of 2024-04-19 03:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found