Skip to content
Advertisement

What is the result of DateTime operation in MySQL

I tried the following SQL query.

This printed the following output.

I have no idea what the result means. I know that we can use TIMESTAMPDIFF to calculate difference between two datetime. Does anyone know what the result means?

Advertisement

Answer

MySQL has an unnerving tendency to treat date/time values as numbers or strings, rather than as date/times. Often, this is not important because the values are readily converted to date/times.

But, for the values in the your question, the representations are:

The result you are getting is 20191201155900 - 20191129155554.

This happens because - is an operator on numbers, and numbers have a higher preference. It can also happen with +, but that can be fixed by adding interval to the expression.

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement