I am looking for an efficient Perl way to replace the following bash command or MySQL statement

bash: date -d"1899-12-30 +40254 days" MySQL: DATE_ADD('1899-12-30', interval 40254 day)

Both export '2010-03-17'. I need to find a reliable and efficient Perl way or a small neat Perl module to handle the same thing, any recommendations?

Thank in advance

lihao

Update: Thanks guys for all suggestions. I am actually looking for some lighter solution or new Perl modules which I don't know. the target is to transfer the parsed Excel datetime into MySQL datetime format. In some 32-bit Linux box, i.e. 32bit RHEL5, the -d switch on the date command does NOT work for all datetime. Since I only care about the exact date instead of time, I am using the following formula to handle the date transfer(where 2209143600 is the second from "1899-12-30 00:00:00" on local to "1970-01-01 00:00:00" by a bash line date -d '1899-12-30 00:00:00' +%s)

sub get_excel_date { return if not $_[0]; my $date = shift; my @x = localtime($date*24*3600 - 2209143600); return sprintf("%04d-%02d-%02d", $x[5]+1900, $x[4]+1, $x[3]); }

In reply to Looking for an efficient way to do datetime transfer by lihao

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.