gpt4 book ai didi

mysql - 使用 str_to_date 转换日期格式

转载 作者:行者123 更新时间:2023-11-29 08:50:59 24 4
gpt4 key购买 nike

在我的 Mysql 数据库表中,日期以 31-Jan-05 的格式存储。我正在尝试将此格式转换为 2005-01-31,然后再将其插入其他表中。我已经尝试过这种方式 str_to_date(exam_date, '%d%M%Y'),但遇到以下错误

Incorrect datetime value: '31-Jan-05' for function str_to_time

我不能使用 str_to_date 将日期格式从 31-Jan-05 更改为 2005-01-31 吗?

提前致谢。

最佳答案

是的。但你有两个问题。

  1. 第二个参数是当前日期格式。 (即字符串)
  2. 您需要采用正确的格式(即 %b 而不是 %M)。

阅读docs the for str_to_date() .

str_to_date(exam_date, '%d-%b-%y')

注意:如果您没有零填充日期,则需要使用 %e 而不是 %d

关于mysql - 使用 str_to_date 转换日期格式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11230444/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com