0

我必须找到两个日期的差异(日期必须从字符串转换为日期格式)。我正在使用以下 mysql 查询

SELECT DATEDIFF
(
        (SELECT STR_TO_DATE(create_date, '%e %b %Y  %k:%i') AS create_date FROM booking) AS date1
        ,
        (SELECT STR_TO_DATE(start_date, '%e %b %Y  %k:%i') AS start_date FROM booking) AS date2
) diff 

单独的内部查询成功地工作。日期格式正确转换,例如从5 Mar 1985 2:331985-03-05 02:33:00

4

1 回答 1

2

是什么阻止你

SELECT
  DATEDIFF( 
    STR_TO_DATE(create_date, '%e %b %Y  %k:%i'),
    STR_TO_DATE(start_date, '%e %b %Y  %k:%i')
  ) AS diff
FROM booking
于 2012-09-10T10:54:07.840 回答