DATEDIFF()函数

时间:2012-09-10 10:51:46

标签: mysql datediff

我必须找到两个日期的差异(日期必须从字符串格式转换为日期格式)。我正在使用以下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:33转换为1985-03-05 02:33:00

1 个答案:

答案 0 :(得分: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