Python 在cherrypy中插入日期时间数据类型的mysql数据库查询

Python 在cherrypy中插入日期时间数据类型的mysql数据库查询,python,mysql,python-2.7,datetime,cherrypy,Python,Mysql,Python 2.7,Datetime,Cherrypy,这是我的插入查询,它工作正常 db = MySQLdb.connect(host="localhost",user="root",passwd="", db="databseFile") cur = db.cursor() print "source_id is: ",srcId[0] cur.execute('INSERT into config(col_1,col_2) values("%s","%s")'%(detail_1,detail_2)) db.commit

这是我的插入查询,它工作正常

db = MySQLdb.connect(host="localhost",user="root",passwd="", db="databseFile")
cur = db.cursor()
    print "source_id is: ",srcId[0]
    cur.execute('INSERT into config(col_1,col_2) values("%s","%s")'%(detail_1,detail_2))
    db.commit()
    cur.close()
下面是如何在python中获取日期时间:

from datetime import datetime
currentTime=datetime.now().strftime('%Y-%m-%d %H:%M:%S')
我想将currentTime插入我的配置表。datetime的数据类型是什么?我在网上搜索过,但没有找到任何解决方案。我的问题是,如何编写插入查询以在数据库中插入日期时间(我使用的是cherrypy和mysql)。

我想要这样的东西:

cur.execute('INSERT into config(col_1,col_2,col_3) values("%s","%s","WhatToWriteHere???")'%(detail_1,detail_2, currentTime))

您正在寻找的可能是一个内置函数,它存在于MySQL-
NOW()
中。以下是您可以如何使用它:

cur.execute('INSERT INTO config(col_1, col_2, col_3) values("%s", "%s", NOW())' % (detail_1, detail_2))

另外,通常情况下,您会使用一些ORM与DB进行接口,而无需以更干净、更安全的方式进行原始SQL查询。看看。

只需使用mysql中内置的
now()
函数:
插入表(日期字段)值(now())@webKnjaZ..我不能,因为我的名声不到15岁