'Incorrect datetime value: Tue Jul 27 2021 20:47:50 GMT+0530 (India Standard Time)

I trying to store date in mysql workbench as "2022-07-27T15:17:50.401Z" but while executing the query it gets converted to the brlow and give this error

I want to store date as this format - "2022-07-27T15:17:50.401Z"

and what should I put the datatype of that column

Data truncation: Incorrect datetime value: 'Tue Jul 27 2021 20:47:50 GMT+0530 (India Standard Time)' for column

EDIT

this is the object -

date range: { from: 2021-07-27T15:52:34.173Z, to: 2022-07-27T15:52:34.173Z },

and the query is :

Insert into table (from , to) Values (FIDataRange.from, FIDataRange.to); 


Solution 1:[1]

Your invalid DATETIME value must be converted using STR_TO_DATE() function.

SELECT STR_TO_DATE('2021-07-27T15:52:34.173Z', '%Y-%m-%dT%H:%i:%s.%f')
| STR_TO_DATE('2021-07-27T15:52:34.173Z', '%Y-%m-%dT%H:%i:%s.%f') |
| :-------------------------------------------------------------- |
| 2021-07-27 15:52:34.173000                                      |

db<>fiddle here

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Akina