getting frustratingly murderous at this one ... !

I am analysing a LibreOffice Calc spreadsheet and need to manipulate a date field.

The values are seemingly read in OK but the parsing is not working somehow.

Code replicated below - ignore the positioning of the use statements, just trying to fathom out what is going on/how to get the result that I need and there are several spurious statements present that can probably be/will be redacted, including the print ones that I am using for monitoring purposes. The main If...then...else is still present due to having read in different formats previously (as alluded to) and finding that strptime gave different returns than I was expecting, hence the extra call to ParseDate

Date format used is in UK style dd/mm/YYYY

The date of 31/08/2024 works OK when read in

The data of 01/09/2024 (ie the next calendar day) gives gibberish - with the day coming out as 09 instead of 1, month as 01 instead of 9 and the year as 124.

Note that I have tried specifying the Zone in the ParseDate call but when I set it to GMT, the perl throws up an error about using barewords and using the directive of "ZONE => " does not help

I have tried various parsing calls using different utilities but I can't find one that behaves itself and consistently provides the correct answer or needs the parameters in a specific format (not impossible to do, just seems to be extra, unnecessary work)

I have also tried stepping through the relevant calls (eg strptime) at debugging run time but my perl is not good enough to decipher what is going on with the pattern matching algorithm

Therefore - any recommendations to code alterations/other better-behaved utilities would be gratefully received.

Also - anyone know why ParseDate returns a month one less than it should ?

many thanks

ADB
... code is read into $lCell variable ... $lCell .= ""; # Force read detail into a string format, just in cas +e (as I have seen ... !) use Date::Parse; use Date::Manip; print ("$lCell ...\t"); my @ttt = strptime ($lCell); my $yyy = ParseDate ($lCell,,); #print "ADB $yyy...\n"; if ($yyy ne "") { # Format originally read was in the format 2024-08-09 before c +onverting to string format #code. $lDay = substr($yyy,6,2); $lMonth = substr($yyy,4,2); $lYear = substr($yyy,0,4); } else { # Format was originally 16-08-2024 or similar $lDay = $ttt[5]; # NOTE HERE that the month range in some perl modules has a ra +nge 0..1 NOT 1..12, so adjust $lMonth = $ttt[4] +1; $lYear = $ttt[3]; }

In reply to date parsing by gsd4me

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.