开发者

String to DATETIME in MySQL

开发者 https://www.devze.com 2023-03-17 10:16 出处:网络
I would like to convert string开发者_如何学Gos to datetime objects to be used in the insert statement for MySQL. The strings are received in the following format :

I would like to convert string开发者_如何学Gos to datetime objects to be used in the insert statement for MySQL. The strings are received in the following format :

2010-12-21T22:57:04.000Z

The data type of the MySQL column is DATETIME.


You can use the strptime function.

For instance, that would give:

myDatetime = datetime.strptime(myString.split(".")[0], "%Y-%m-%dT%H:%M:%S")

[EDIT] Well, I've seen this has been treated in another thread with a better answer than mine: How to parse an ISO 8601-formatted date?

0

精彩评论

暂无评论...
验证码 换一张
取 消