I have a VBA in excel to transfer data to MySQL, however I have issues with the date
I have a VBA in excel to transfer data to MySQL, however I have issues with the date. The error I get is
Runtime Error: 2147467259 (8004005): Incorrect datetime value: for
function str_to_date.
This is my code:
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 & ");"
mysql sql excel vba
add a comment |
I have a VBA in excel to transfer data to MySQL, however I have issues with the date. The error I get is
Runtime Error: 2147467259 (8004005): Incorrect datetime value: for
function str_to_date.
This is my code:
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 & ");"
mysql sql excel vba
well, what value is inOut_of_Dock_Time
when the error occurs? Or maybe the problem is withFILEDATETIME1
.One of these variables, or possibly even both, is likely to be the issue
– ADyson
Nov 14 '18 at 19:18
The value for Out_of_Dock_Time is 04/10/18 17:26. and will be in this format itself. The format for Fieldatetime1 is 04/10/18 17:26: PM
– iti
Nov 14 '18 at 20:11
Hi @ADyson This is how I have defined my Out_of_dock time, could this be the reason? Out_of_Dock_Time = Format(XLsheet.Cells(i, CommodityCOl + 10).Value, "MM/dd/yy HH:mm:ss")
– iti
Nov 14 '18 at 20:26
add a comment |
I have a VBA in excel to transfer data to MySQL, however I have issues with the date. The error I get is
Runtime Error: 2147467259 (8004005): Incorrect datetime value: for
function str_to_date.
This is my code:
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 & ");"
mysql sql excel vba
I have a VBA in excel to transfer data to MySQL, however I have issues with the date. The error I get is
Runtime Error: 2147467259 (8004005): Incorrect datetime value: for
function str_to_date.
This is my code:
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 & ");"
mysql sql excel vba
mysql sql excel vba
edited Nov 14 '18 at 21:01
ADyson
24.9k112646
24.9k112646
asked Nov 14 '18 at 17:15
itiiti
1
1
well, what value is inOut_of_Dock_Time
when the error occurs? Or maybe the problem is withFILEDATETIME1
.One of these variables, or possibly even both, is likely to be the issue
– ADyson
Nov 14 '18 at 19:18
The value for Out_of_Dock_Time is 04/10/18 17:26. and will be in this format itself. The format for Fieldatetime1 is 04/10/18 17:26: PM
– iti
Nov 14 '18 at 20:11
Hi @ADyson This is how I have defined my Out_of_dock time, could this be the reason? Out_of_Dock_Time = Format(XLsheet.Cells(i, CommodityCOl + 10).Value, "MM/dd/yy HH:mm:ss")
– iti
Nov 14 '18 at 20:26
add a comment |
well, what value is inOut_of_Dock_Time
when the error occurs? Or maybe the problem is withFILEDATETIME1
.One of these variables, or possibly even both, is likely to be the issue
– ADyson
Nov 14 '18 at 19:18
The value for Out_of_Dock_Time is 04/10/18 17:26. and will be in this format itself. The format for Fieldatetime1 is 04/10/18 17:26: PM
– iti
Nov 14 '18 at 20:11
Hi @ADyson This is how I have defined my Out_of_dock time, could this be the reason? Out_of_Dock_Time = Format(XLsheet.Cells(i, CommodityCOl + 10).Value, "MM/dd/yy HH:mm:ss")
– iti
Nov 14 '18 at 20:26
well, what value is in
Out_of_Dock_Time
when the error occurs? Or maybe the problem is with FILEDATETIME1
.One of these variables, or possibly even both, is likely to be the issue– ADyson
Nov 14 '18 at 19:18
well, what value is in
Out_of_Dock_Time
when the error occurs? Or maybe the problem is with FILEDATETIME1
.One of these variables, or possibly even both, is likely to be the issue– ADyson
Nov 14 '18 at 19:18
The value for Out_of_Dock_Time is 04/10/18 17:26. and will be in this format itself. The format for Fieldatetime1 is 04/10/18 17:26: PM
– iti
Nov 14 '18 at 20:11
The value for Out_of_Dock_Time is 04/10/18 17:26. and will be in this format itself. The format for Fieldatetime1 is 04/10/18 17:26: PM
– iti
Nov 14 '18 at 20:11
Hi @ADyson This is how I have defined my Out_of_dock time, could this be the reason? Out_of_Dock_Time = Format(XLsheet.Cells(i, CommodityCOl + 10).Value, "MM/dd/yy HH:mm:ss")
– iti
Nov 14 '18 at 20:26
Hi @ADyson This is how I have defined my Out_of_dock time, could this be the reason? Out_of_Dock_Time = Format(XLsheet.Cells(i, CommodityCOl + 10).Value, "MM/dd/yy HH:mm:ss")
– iti
Nov 14 '18 at 20:26
add a comment |
1 Answer
1
active
oldest
votes
Your format string
'%m/%d/%Y %h:%i:%s'
is incorrect. As per the documentation on date format specifiers, %h
represents hours in 12hr format (i.e. 01-12). Instead you need to use %H
to read 24hr times. The correct format string is
'%m/%d/%Y %H:%i:%s'
Click here for a demo using SQLFiddle
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53305543%2fi-have-a-vba-in-excel-to-transfer-data-to-mysql-however-i-have-issues-with-the%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Your format string
'%m/%d/%Y %h:%i:%s'
is incorrect. As per the documentation on date format specifiers, %h
represents hours in 12hr format (i.e. 01-12). Instead you need to use %H
to read 24hr times. The correct format string is
'%m/%d/%Y %H:%i:%s'
Click here for a demo using SQLFiddle
add a comment |
Your format string
'%m/%d/%Y %h:%i:%s'
is incorrect. As per the documentation on date format specifiers, %h
represents hours in 12hr format (i.e. 01-12). Instead you need to use %H
to read 24hr times. The correct format string is
'%m/%d/%Y %H:%i:%s'
Click here for a demo using SQLFiddle
add a comment |
Your format string
'%m/%d/%Y %h:%i:%s'
is incorrect. As per the documentation on date format specifiers, %h
represents hours in 12hr format (i.e. 01-12). Instead you need to use %H
to read 24hr times. The correct format string is
'%m/%d/%Y %H:%i:%s'
Click here for a demo using SQLFiddle
Your format string
'%m/%d/%Y %h:%i:%s'
is incorrect. As per the documentation on date format specifiers, %h
represents hours in 12hr format (i.e. 01-12). Instead you need to use %H
to read 24hr times. The correct format string is
'%m/%d/%Y %H:%i:%s'
Click here for a demo using SQLFiddle
answered Nov 14 '18 at 21:03
ADysonADyson
24.9k112646
24.9k112646
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53305543%2fi-have-a-vba-in-excel-to-transfer-data-to-mysql-however-i-have-issues-with-the%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
well, what value is in
Out_of_Dock_Time
when the error occurs? Or maybe the problem is withFILEDATETIME1
.One of these variables, or possibly even both, is likely to be the issue– ADyson
Nov 14 '18 at 19:18
The value for Out_of_Dock_Time is 04/10/18 17:26. and will be in this format itself. The format for Fieldatetime1 is 04/10/18 17:26: PM
– iti
Nov 14 '18 at 20:11
Hi @ADyson This is how I have defined my Out_of_dock time, could this be the reason? Out_of_Dock_Time = Format(XLsheet.Cells(i, CommodityCOl + 10).Value, "MM/dd/yy HH:mm:ss")
– iti
Nov 14 '18 at 20:26