user1369905
user1369905

Reputation: 693

DATEDIFF() function

I have to find the difference in two dates (dates have to converted from string to date format). I am using the following mysql query

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 

Individually the inner queries work successfully. The date format is correctly converted for example from 5 Mar 1985 2:33 to 1985-03-05 02:33:00

Upvotes: 0

Views: 1226

Answers (1)

Eugen Rieck
Eugen Rieck

Reputation: 65274

What is stopping you from

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

Upvotes: 2

Related Questions