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

Some of you Might have realized from Waiting ... That I am new to Perl OLE usage. I now have the following Problem: I have times in this format:
00/01/1900 00:31:00
I am retreiving these times with the follwing piece of code:
if ( ref( $value ) =~ /Variant/ ){ if ( $iRef == 4 || $iRef == 6 ){ $value = $value->Date( "dd/MM/yy" ); } elsif ( $iRef == 5 || $iRef == 7 ){ $value = $value->Time( "hh:mm:ss" ); } } if ( $values ne "" && $value =~ /^\d?\.\d*$/ ){ print $value; my $seconds = $value * 60 * 60 * 24; print $seconds; my ( undef, undef, undef, $hour,$min,$sec)= Date::Calc::Add_Delta_ +DHMS( 1900, 1, 1, 0, 0, 0, 0,0,0, $seconds); $value = sprintf( "%02u:%02u:%02u", $hour, $min, $sec ); }
The second bit is used to convert non-Variant times to a time format. Unfortunately the time in the example above is converted as "12:31:00", which as you might imagine has some unpleasant effects. Has anyone any ideas how to tackle this? I am using AS Perl 5.8.6 and Excel 2002. Thank you for all help.

Cheers,
PerlingTheUK

Replies are listed 'Best First'.
Re: Perl OLE Time Formatting Error!?
by NetWallah (Canon) on Jun 01, 2005 at 02:43 UTC
    Have you considered using
    DateTime::Format::Excel ?
    use DateTime::Format::Excel; # From Excel via class method: my $datetime = DateTime::Format::Excel->parse_datetime( 37680 ); # OR retrieve $value->Date(<Whatever syntax works here>) print $datetime->ymd('.'); # '2003.02.28'

         "There are only two truly infinite things. The universe and stupidity, and I'm not too sure about the universe"- Albert Einstein

      Did not try this, But it was a stupid Error and one more or less for a VB group:
      $value12hour = $value->Time( "hh:mm:ss" ); $value24hour = $value->Time( "HH:mm:ss" );
      I guess this is selfexplanatory.

      Cheers,
      PerlingTheUK