

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
MySQL query to convert timediff() to seconds?
For this, you can use TIME_TO_SEC() function. Let us first create a table −
mysql> create table DemoTable -> ( -> SourceTime time, -> DestinationTime time -> ); Query OK, 0 rows affected (1.33 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable values('10:20:00','4:50:54'); Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable values('12:05:10','7:45:12'); Query OK, 1 row affected (0.30 sec)
Display all records from the table using select statement −
mysql> select *from DemoTable;
Output
This will produce the following output −
+------------+-----------------+ | SourceTime | DestinationTime | +------------+-----------------+ | 10:20:00 | 04:50:54 | | 12:05:10 | 07:45:12 | +------------+-----------------+ 2 rows in set (0.00 sec)
Following is query to convert the time difference to seconds −
mysql> SELECT ABS(TIME_TO_SEC(timediff(DestinationTime, SourceTime))) from DemoTable;
Output
This will produce the following output −
+---------------------------------------------------------+ | ABS(TIME_TO_SEC(timediff(DestinationTime, SourceTime))) | +---------------------------------------------------------+ | 19746 | | 15598 | +---------------------------------------------------------+ 2 rows in set (0.00 sec)
- Related Questions & Answers
- MySQL convert timediff output to day, hour, minute, second format?
- How to convert JavaScript seconds to minutes and seconds?
- MySQL query to convert timestamp to month?
- MySQL query to extract time in a format without seconds
- Convert HH:MM:SS to seconds with JavaScript?
- Python program to convert seconds into hours, minutes and seconds
- MySQL Query to convert from datetime to date?
- MySQL query to convert height format to centimeters?
- MySQL query to convert empty values to NULL?
- Convert output of MySQL query to UTF8?
- What is the equivalent of MySQL TIME_TO_SEC() method in PHP to convert datetime to seconds?
- How to convert time seconds to h:m:s format in Python?
- How to convert seconds to HH-MM-SS with JavaScript?
- MySQL query to convert a single digit number to two-digit
- MySQL query to convert a string into a month (Number)?
Advertisements