gpt4 book ai didi

php - 将文本列转换为时间

转载 作者:行者123 更新时间:2023-11-29 02:58:15 26 4
gpt4 key购买 nike

我有一个名为“slots”的表,其中有一列的值是时间段(例如上午 8:00、上午 9:00、上午 9:30 等)。但是这些值存储为文本。我想将它们转换为时间。我尝试了以下查询

UPDATE 'slots' SET 'slot' = STR_TO_TIME('slot', '%h:%i %p')

但是报错如下

#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''slots' SET 'slot' = STR_TO_TIME('slot', '%h:%i %p')' at line 1

最佳答案

你需要使用反引号

UPDATE `slots` SET `slot` = TIME_FORMAT(TIME( STR_TO_DATE( `slot`, '%h:%i %p' ) ), '%h:%i %p' );

现在它被用作文字字符串而不是列。反引号表示列或表名而不是引号

关于php - 将文本列转换为时间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27700139/

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