Thanks to Corion, I managed to do it. Here is what I needed to get an Excel format timestamp (I added some comment, to make it easier to understand) :

# This function will return 1 if it is a leap year, or 0 if it's not sub LeapYear { my ($iYear) = @_; return 1 if ( $iYear == 1900 ); return ( ( ( $iYear % 4 ) == 0 ) && ( ( $iYear % 100 ) || ( $iYear % 400 ) == 0 ) ) ? 1 : 0; } sub LocaltimeExcel { my ( $iSec, $iMin, $iHour, $iDay, $iMon, $iYear, $iwDay, $iMSec ) += @_; # Changing year and month to the right format $iMon++; $iYear += 1900; # Time calculation my $iTime; $iTime = $iHour; $iTime *= 60; $iTime += $iMin; $iTime *= 60; $iTime += $iSec; $iTime += $iMSec / 1000.0 if ( defined($iMSec) ); $iTime /= 86400.0; #3600*24 my $iY; my $iYDays; # Date calculation $iY = 1900; $iYDays = 366; while ( $iY < $iYear ) { $iTime += $iYDays; $iY++; $iYDays = ( LeapYear($iY) ) ? 366 : 365; } for ( my $iM = 1 ; $iM < $iMon ; $iM++ ) { if ( $iM == 1 || $iM == 3 || $iM == 5 || $iM == 7 || $iM == 8 || $iM == 10 || $iM == 12 ) { $iTime += 31; } elsif ( $iM == 4 || $iM == 6 || $iM == 9 || $iM == 11 ) { $iTime += 30; } elsif ( $iM == 2 ) { $iTime += ( LeapYear($iYear) ) ? 29 : 28; } print LeapYear($iYear) . "\n"; } $iTime += $iDay; return $iTime; }

These are the modified functions I copied in Spreadsheet::ParseExcel::Utility. You can use them like the following (for example) :

($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time +); my $timestamp = &LocaltimeExcel( $sec, $min, $hour, $mday, $mon, $year + ); $timestamp =~ s/\./\,/; print $timestamp;

Here, I convert the current localtime into what I need. I hope this will be useful for someone else.

Thanks Monks !

Varkh


In reply to Re: Using Excel timestamp with perl by Varkh
in thread Using Excel timestamp with perl by Varkh

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.