かずきち。の日記

Pythonエンジニア&元東大生のつぶやき

date型、time型、datetime型の変換

//datetime型の列を追加

ALTER TABLE program ADD start datetime;

//datetime型の列を追加

ALTER TABLE program ADD end datetime;

//Pythonにて…Nullになってしまうものが存在

import MySQLdb

print

connect = MySQLdb.connect(db="tv", host="localhost", port=3306, user="root", passwd="")

cur = connect.cursor()

cur.execute('select * from program')
rows = cur.fetchall()

for row in rows:
    print row[2]
    print row[3]
    date = str(row[2])
    time = str(row[3])
    if date != "None":
        sql = "UPDATE program SET start = '"+date+" "+time+"' where from_date = '"+date+"' AND from_time = '"+time+"'"
        print sql
        cur.execute(sql)
    
    
cur.close()
広告を非表示にする