Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
4 views
in SQL by (20.3k points)

How to calculate the difference between two dates, in the format YYYY-MM-DD hh: mm: ss and to get the result in seconds or milliseconds?

1 Answer

0 votes
by (40.7k points)

Try using TIMESTAMPDIFF like this:

SELECT TIMEDIFF('2007-12-31 10:02:00','2007-12-30 12:01:01');

-- result: 22:00:59, the difference in HH:MM:SS format

SELECT TIMESTAMPDIFF(SECOND,'2007-12-30 12:01:01','2007-12-31 10:02:00'); 

-- result: 79259  the difference in seconds

Related questions

0 votes
2 answers
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
asked Jul 16, 2019 in SQL by Tech4ever (20.3k points)

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...