Our Python CMS stores some date values in a generic ‘attribute’ table’s varchar column. Some of these dates are later moved into a table with an actual date column. If the CMS user entered an invalid date, it doesn’t get caught until the migration, when the query fails with an ‘Invalid string date’ error.
How can I use Python to make sure that all dates put into our CMS are valid Oracle string date representations?
I’d change the approach a bit. Have Python parse the original date input as forgivingly as possible, then output the date in a known-good representation.
dateutil‘s liberal parser may be a good place to start:
I’m not sure ‘%d-%b-%y’ is actually still the right date format for Oracle, but it’ll probably be something similar, ideally with four-digit years and no reliance on month names. (Trap: %b is locale-dependent so may return unwanted month names on a non-English OS.) Perhaps “strftime(‘%Y-%m-%d’)” followed by “TO_DATE(…, ‘YYYY-MM-DD’)” at the Oracle end is needed?