days between 01 and 28-31 (depending on the month, leap year)
A quick lookup for GNU Awk’s time functions points to mktime("YYYY MM DD HH MM SS")
Let’s try it:
Looking good! How about something wrong?
Oh yeah! What about a “bad” date?
Wait, what?! Oh no……..
Going Full Circle
If invalid dates returned -1, we would be done by now.
1760684400 is 2025-10-17 … mktime takes 44 and 78 and (probably) multiplies those by seconds-per-month, and
seconds-per-day.
When I looked at the other time functions,
there didn’t seem to be anything that helped either.
The eureka! was to think about using the invalid date to format a date back to ISO
8601 format. If the input and output dates are different, the date is wrong!
Sidenote: I’m using %F to format dates. man 3 strftime says:
%F Equivalent to %Y-%m-%d (the ISO 8601 date format)
Test Script
Here’s my test cases:
The Awk script:
Results:
I was surprised that pre-1970 (epoch) also worked! Their mktime values are negative: