lihao has asked for the wisdom of the Perl Monks concerning the following question:
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]); }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Looking for an efficient way to do datetime transfer
by Corion (Patriarch) on Mar 30, 2010 at 17:22 UTC | |
by lihao (Monk) on Mar 30, 2010 at 17:39 UTC | |
by Corion (Patriarch) on Mar 30, 2010 at 17:42 UTC | |
by ikegami (Patriarch) on Mar 30, 2010 at 17:46 UTC | |
by ww (Archbishop) on Mar 30, 2010 at 17:48 UTC | |
|
Re: Looking for an efficient way to do datetime transfer
by ikegami (Patriarch) on Mar 30, 2010 at 17:42 UTC | |
|
Re: Looking for an efficient way to do datetime transfer
by moritz (Cardinal) on Mar 30, 2010 at 19:53 UTC | |
|
Re: Looking for an efficient way to do datetime transfer
by ambrus (Abbot) on Mar 31, 2010 at 13:12 UTC |