gpt4 book ai didi

php - 将日期插入 MySQL 的最佳方法

转载 作者:行者123 更新时间:2023-11-29 02:01:17 25 4
gpt4 key购买 nike

我得到一个文本文件转储,我正在通过 PHP 将其处理到 MySQL 中,日期格式看起来像“2012 年 7 月”或“2012 年 12 月”等。我想以我可以的方式将它们插入数据库然后按日期选择将来的记录。有没有什么方法可以事先将它们转换为正确的格式,或者有什么方法可以让 SQL 通过函数自动转换?

非常感谢。

最佳答案

Is there any way to convert these to the right format prior or a way to get SQL to automatically convert via a function?

使用 MySQL 的 STR_TO_DATE() 将其保持在数据库级别.

例如:

SELECT STR_TO_DATE('Dec 2012','%b %Y');

关于php - 将日期插入 MySQL 的最佳方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14221384/

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