- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Difference between two timestamps in seconds in MySQL?
Let us now see the following methods to calculate the time difference between two timestamps in seconds.
Method
The following is the query to calculate the difference between two timestamps.
mysql> SELECT TIMESTAMPDIFF(SECOND, '2018-10-17 11:51:55', '2018-10-17 11:51:58');
The following is the output in seconds.
+---------------------------------------------------------------------+ | TIMESTAMPDIFF(SECOND, '2018-10-17 11:51:55', '2018-10-17 11:51:58') | +---------------------------------------------------------------------+ | 3 | +---------------------------------------------------------------------+ 1 row in set (0.00 sec)
Method 2
The following is the query to calculate the difference between two timestamps with the help of UNIX Timestamp.
mysql> SELECT UNIX_TIMESTAMP('2018-10-17 11:57:50') - UNIX_TIMESTAMP('2018-10-17 11:57:45') as DifferenceInSeconds;
The following is the output in seconds.
+---------------------+ | DifferenceInSeconds | +---------------------+ | 5 | +---------------------+ 1 row in set (0.00 sec)
- Related Articles
- MySQL difference between two timestamps in Seconds?
- Get the difference between two timestamps in seconds in MySQL?
- How to get time difference between two timestamps in seconds?
- Find the difference between two timestamps in days with MySQL
- What is the difference between UNIX TIMESTAMPS and MySQL TIMESTAMPS?
- How to get the seconds and minutes between two Instant timestamps in Java
- Python program to find difference between two timestamps
- C# Program to get the difference between two dates in seconds
- Difference between two selects in MySQL?
- Sorted difference between two columns in MySQL?
- How to get the duration between two Instant timestamps in Java
- Finding difference in Timestamps – Python Pandas
- How to compare timestamps in MySQL?
- Java Program to get the difference between two time zones by seconds
- Difference between TimeSpan Seconds() and TotalSeconds()

Advertisements