2

I have two columns that have time data that looks like "2017-12-06 18:50:27 +0000" . What MySQL function can I use to get the difference in hours of the two date time strings? I tried DATEDIFF(time_string_1, time_string_2) but it isn't working. What else can I use?

2

2 Answers 2

3

You can use the timestampdiff function:

SELECT TIMESTAMPDIFF(HOUR, col1, col2)
FROM   mytable
2

Use TIMESTAMPDIFF function.

Syntex:

TIMESTAMPDIFF(unit,datetime_expr1,datetime_expr2)

Where Unit is:

Microseconds, Seconds, Minutes, Hours, Days, Weeks, Months, Quarters, Years.

Query:

select TIMESTAMPDIFF(HOUR, time_string_1, time_string_2) 
from table_name

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.