Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

MySQL TIMESTAMPDIFF returns 0 even though there is 1 hour difference between two values

I feel like I am doing something wrong but I cannot understand what.

Let’s say I have a query:

select timestampdiff(minute, '2022-10-31t11:25:00.000', '2022-10-31t12:25:00.000')

It returns 0 but it should return 60, no? There is a 1 hour difference between the two. It returns anything other than 0 only if the date is different. What is wrong here?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Your query is not using valid MySQL timestamp literals. If you want a T separator between the date and time portions of the timestamps, it must be uppercase. From the MySQL documentation:

The date and time parts can be separated by T rather than a space. For example, ‘2012-12-31 11:30:45’ ‘2012-12-31T11:30:45’ are equivalent.

SELECT TIMESTAMPDIFF(minute,
                     '2022-10-31T11:25:00.000',
                     '2022-10-31T12:25:00.000');  -- 60
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading