如何将包含日期的字符串转换为MySQL时间戳格式?
我在Python环境中工作。我有一个像这样的日期字符串 - 2022年4月26日17:23:17 GMT
我想将此日期插入MySQL,其中日期列数据类型为时间戳。我该如何实现?
My variables are like this (id=1, name="Jack", date="26 Apr 2022 17:23:17 GMT")
mycurser = mydb.cursor()
sql = "INSERT INTO sample_table (id,name,date) VALUES (%s, %s, %s)"
val = (id, name, date)
mycurser.execute(sql,val)
这里日期是字符串,MySQL数据类型是时间戳。
I am working in python environment. I have a date string which is like this - 26 Apr 2022 17:23:17 GMT
I want to insert this date into mysql where the date column datatype is timestamp. How can I achieve this?
My variables are like this (id=1, name="Jack", date="26 Apr 2022 17:23:17 GMT")
mycurser = mydb.cursor()
sql = "INSERT INTO sample_table (id,name,date) VALUES (%s, %s, %s)"
val = (id, name, date)
mycurser.execute(sql,val)
Here date is string and mysql datatype is timestamp.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用
str_to_date
:使用Python脚本:
You could use
STR_TO_DATE
:Using your Python script: