
- Learn MySQL
- MySQL - Home
- MySQL - Introduction
- MySQL - Installation
- MySQL - Administration
- MySQL - PHP Syntax
- MySQL - Connection
- MySQL - Create Database
- MySQL - Drop Database
- MySQL - Select Database
- MySQL - Data Types
- MySQL - Create Tables
- MySQL - Drop Tables
- MySQL - Insert Query
- MySQL - Select Query
- MySQL - Where Clause
- MySQL - Update Query
- MySQL - Delete Query
- MySQL - Like Clause
- MySQL - Sorting Results
- MySQL - Using Join
- MySQL - NULL Values
- MySQL - Regexps
- MySQL - Transactions
- MySQL - Alter Command
- MySQL - Indexes
- MySQL - Temporary Tables
- MySQL - Clone Tables
- MySQL - Database Info
- MySQL - Using Sequences
- MySQL - Handling Duplicates
- MySQL - SQL Injection
- MySQL - Database Export
- MySQL - Database Import
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 Articles
- MySQL convert timediff output to day, hour, minute, second format?
- MySQL query to convert timestamp to month?
- MySQL query to extract time in a format without 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?
- How to convert JavaScript seconds to minutes and seconds?
- Convert HH:MM:SS to seconds with JavaScript?
- Python program to convert seconds into hours, minutes and seconds
- MySQL query to convert a single digit number to two-digit
- MySQL query to convert a string into a month (Number)?
- What is the equivalent of MySQL TIME_TO_SEC() method in PHP to convert datetime to seconds?
- How to convert US date format to MySQL format in INSERT query?
- How to convert date YYYYMMDD to YY-MM-DD in MySQL query?

Advertisements