How to check the date validity?

Chris Angelico rosuav at gmail.com
Mon Dec 23 19:39:24 EST 2013


On Tue, Dec 24, 2013 at 11:30 AM, Igor Korot <ikorot01 at gmail.com> wrote:
> So, my question is: since there is a simple way of inserting
> preformatted string into the datetime field of mySQL, how do I
> validate the date string?

Well, the easiest way would be to simply attempt the SQL query. If it
comes back with an error, the date wasn't valid. To protect a
transaction against being broken by an error, you can use a SAVEPOINT
- check the database docs. (I've never actually used savepoints in
MySQL, only PostgreSQL, so things may be a bit different. Check the
docs.)

ChrisA



More information about the Python-list mailing list