troubleshooting Question

Validating Python Date string before MySQL insert

Avatar of cyber-33
cyber-33Flag for United States of America asked on
Python
3 Comments1 Solution660 ViewsLast Modified:
I am reading some dates values from XML documents and generating MySQL insert statements. Some date values refer to month and year and are in the following format: "YYYYMo00"

For example, May 2010, would be recorded as "20100500". Although the date is expressed as "00", MySql accepts the inserts statement into the date value without any problems.

Some datevalues are incorrect (e.g. "20103400"). In this example the months cannot be 34. MySql server does not process this insert and I need to catch these improper dates prior to sending them to MySql.

QUESTION:
How to validate strings representing dates prior to generating the MySQL Insert Statement?

I have tried using dateutil.parser.parse() function to validate the strings. This did not work because the function thought "20103400" were not valid, while MySQL Server can clearly accept these values.

I need a solution that validates date strings, while accepting the "20103400" format.

Thank you!
ASKER CERTIFIED SOLUTION
farzanj

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 3 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 3 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros