w3resource logo

MySQL TIME_TO_SEC function

MySQL TIME_TO_SEC() function


Seondary Nav


MySQL TIME_TO_SEC() converts a time value in to seconds.

Syntax :


Where tm is a time.

Pictorial Presentation

Pictorial Presentation of MySQL TIME_TO_SEC() function


Example :

The following statement will convert the specified time 05:15:40 in seconds.

SELECT TIME_TO_SEC('05:15:40');


mysql> SELECT TIME_TO_SEC('05:15:40');
| TIME_TO_SEC('05:15:40') |
|                   18940 | 
1 row in set (0.02 sec)

PHP script

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>example-time_to_sec-function - php mysql examples | w3resource</title>
echo "<h2>Conversion of a given time expression 05:15:40 to seconds : </h2>";
echo "<table border='1' style='border-collapse: collapse;border-color: silver;'>";
echo "<tr style='font-weight: bold;'>";
echo "<td width='100' align='center'>Seconds</td>";
echo "</tr>";
$result = mysql_query("SELECT TIME_TO_SEC('05:15:40')");
echo "<tr>";
echo "<td align='center' width='200'>" . $row["TIME_TO_SEC('05:15:40')"] . "</td>";
echo "</tr>";
echo "</table>";

View the example in browser

All Date and Time Functions :

Click here to see the MySQL Date and time functions.


Looking for some other tutorial?