Convert String In Python to insert into MySQL DB date column date
date, mysql, python
Solution
pip install python-dateutil
from dateutil.parser import parse
date = 'Thu, 14 Mar 2013 13:33:07 -0400'
parse(date).strftime("%Y-%m-%d %H:%M:%S")
Problem
I have an unusual date string that I want to insert into a MySQL DB. ``` date = 'Thu, 14 Mar 2013 13:33:07 -0400' ``` And here is the insert statement ``` self.cursor.execute("INSERT INTO table1 (`DATE`)VALUES (%s);",(date)) ``` When I do it like this it shows up in the database like : ``` 0000-00-00 00:00:00 ``` Even if I enter the SQL manualy it shows up the same way. How do I convert the date string into a mysql readable date for insert?