gsd4me has asked for the wisdom of the Perl Monks concerning the following question:
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]; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: date parsing
by hippo (Archbishop) on Jun 10, 2025 at 21:25 UTC | |
|
Re: date parsing
by ikegami (Patriarch) on Jun 13, 2025 at 10:35 UTC | |
by SBECK (Chaplain) on Jun 23, 2025 at 15:03 UTC | |
|
Re: date parsing
by ysth (Canon) on Jun 13, 2025 at 04:53 UTC | |
|
Re: date parsing
by NERDVANA (Priest) on Jun 13, 2025 at 15:25 UTC |