Hi, I’m trying to move data between two database. One is MySQL and the other Microsoft SQL.
When I try to update a row with a DateTime i’m getting the error
ERROR: Conversion failed when converting date and/or time from character string
I’ve tried to set a new date().toSTRING(), and/or to CAST in a DATETIME, nothing’s working. If I copy paste the “result” in Microsoft SQL and run the row update, it’s working. It looks like N8N does not paste the date as is.
We should be sending the data as it is in the result window there, Do you only have the one input item or is there multiple? Have you tried removing the ' ' from the date as well? I can’t remember if MSSQL has issues with that.
Only one input and if I remove the single quotes, it looks like it’s converting the date to a MM date format because it’s now seeing “NOV” as the month… But my string is still in mm format
That looks ok to me, I would have expected CAST to work. What happens if you make a test table and set the field to be varchar / text then write the value out? It would be interesting to see what is sent, You could also find this in the tsql log in ssms.
If i send it in single quotes to M$ SQL in a varchar field, it gets converted to full datetime. '{{$json["ActualArrival"]}}' → Fri Nov 11 2022 16:54:40 GMT+0000 (Coordinated Universal Time)
Without single quotes : ERROR: Incorrect syntax near 'Nov'.
With Cast : CAST('{{$json["ActualArrival"]}}' AS datetime) → ERROR: Conversion failed when converting date and/or time from character string.
With Regex in Cast, it still converting the datetime in another format : CAST('{{$json["ActualArrival"].replace(/Z/g,'').replace(/T/g,' ')}}' AS datetime) → Jan 1 1900 12:00AM
And if I keep the regex and remove the Cast, the flow is proceeding but no ouput in the SQL row, it’s blank UPDATE temp SET Notes = '{{$json["ActualArrival"].replace(/Z/g,'').replace(/T/g,' ')}}'
I’ve also tried .toString() and same result…
And I just tried on a MYSQL DB and it’s working… So it looks like it’s something on my SQL server or with n8n that does some data manipulation with the SQL connector.