简体   繁体   English

从CSV到mysql传输数据时发生日期时间错误

[英]date time error while transferring data from csv to mysql

I am very new to python and trying to get time from csv file which has location id,vrm.,date,time on it and been inserted into table pay ans display but i need to insert time from csv file , where on table its prints as 00:00:00. 我对python非常陌生,并尝试从具有位置id,vrm。,date,time的csv文件中获取时间并插入到表中,并显示在表中,但我需要从csv文件中插入时间,在表上的打印位置如00:00:00。 how can I get timings from csv instead of entrydatetime 我如何从csv而不是entrydatetime获取时间

tmp = valid_date.split('/')
    iso_date = "%s-%s-%s" % (tmp[2], tmp[1], tmp[0])
    entryDatetime = "%s 00:00:00" % iso_date
    expiryDatetime = "%s 23:59:59" % iso_date
    sql_local = """INSERT INTO customer_1.pay_and_display
        (plate, machine_id, ticket_datetime, expiry_datetime, ticket_name, ticket_price)
        VALUES ("%s", "%s", "%s", "%s", "%s", "%s") """ % (vrm, location_id, entryDatetime, expiryDatetime, "WL", 0)
    print sql_local
    cursor.execute(sql_local)

    curl = pycurl.Curl()
    body = Body()

Ok, so there is time.strptime to parse the string representing a date and the csv module in general to parse a csv file. 好的,所以有time.strptime来解析代表日期的字符串,而csv模块通常来解析csv文件。

Edit: you can also use the strptime classmethod of datetime objects if you're dealing with dates. 编辑:如果要处理日期,还可以使用datetime对象的strptime类方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM