我正在尝试使用 MySQL 函数将 12:00:00 等时间格式转换为秒。我收到消息说 您的 SQL 语法有错误;查看与您的 MySQL 服务器版本对应的手册,了解在 ':00:00 附近使用的正确语法。我能做些什么?有没有格式不能转换?请检查我的代码
这行得通
SELECT TIME_TO_SEC(TIMEDIFF(2014-02-21 12:00:00,2014-02-21 13:00:00)) AS TimeInSecs
FROM Tbl_Time
这不起作用
SELECT TIME_TO_SEC(TIMEDIFF(12:00:00,13:00:00)) AS TimeInSecs
FROM Tbl_Time
最佳答案
你需要用单引号 '
加上日期和时间
SELECT TIME_TO_SEC(TIMEDIFF('12:00:00','13:00:00'));
SELECT TIME_TO_SEC(TIMEDIFF('2014-02-21 12:00:00','2014-02-21 13:00:00')) AS TimeInSecs ;
TIMEDIFF() returns expr1 – expr2 expressed as a time value. expr1 and expr2 are time or date-and-time expressions, but both must be of the same type.
关于php - MySQL - 无法将时间格式转换为秒,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21927253/