我在excel中有一个VBA,可以将数据传输到MySQL,但是日期有问题。我得到的错误是
运行时错误:2147467259(8004005):错误的日期时间值: 函数str_to_date。
这是我的代码:
sql = "Insert Into LeadBoard(Commodity,Last_Broadcast_Job,Material_to_Work, " _ & " Last_Picked_Job,Picked_Lead_Time,Last_Loaded_Job," _ & "Loaded_Lead_Time,Dispatch_Lead_Time,Last_Dispatched_Job," _ & "Out_of_Dock_Time,Last_Dispatched_Rack," _ & "Last_Dispatched_Trailer,Customer_Point_of_Install,Excel_date_time, calc_Material_to_work," _ & "calc_Load_Lead_Time, calc_Picked_Lead_Time,calc_Dispatch_Lead_Time) " _ & " VALUES (" & Commodity & "," & Last_Broadcast_Job & ",'" _ & Material_to_Work & "'," & Last_Picked_Job & ",'" _ & Picked_Lead_Time & "'," & Last_Loaded_Job & ",'" _ & Loaded_Lead_Time & "','" & Dispatch_Lead_Time & "'," _ & Last_Dispatched_Job & "," & "STR_TO_DATE('" & Out_of_Dock_Time & "', '%m/%d/%Y %h:%i:%s' ) ," _ & Last_Dispatched_Rack & "," & Last_Dispatched_Trailer & "," _ & Customer_Point_of_Install & "," & "STR_TO_DATE('" & FILEDATETIME1 & "', '%m/%d/%Y %h:%i:%s' ) ," _ & calc_Material_to_work & "," & calc_Loaded_Lead_Time & "," & calc_Picked_Lead_Time & "," & calc_Dispatch_Lead_Time & ");"
答案 0 :(得分:0)
您的格式字符串
'%m/%d/%Y %h:%i:%s'
不正确。根据日期格式说明符documentation,%h
表示12小时格式的小时(即01-12)。相反,您需要使用%H
来阅读24小时。正确的格式字符串是
'%m/%d/%Y %H:%i:%s'