w3resource logo


MySQL TIME_TO_SEC function

MySQL TIME_TO_SEC() function

rating Average rating 9 out of 10. Total 3 users rated.

<<PreviousNext>>

Description

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

Syntax

TIME_TO_SEC(tm)

Where tm is a time.

Example :

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

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

Output

MySQL TIME_TO_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">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>example-time_to_sec-function - php mysql examples | w3resource</title>
</head>
<body>
<?php
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>";
include("../dbopen.php");
$result = mysql_query("SELECT TIME_TO_SEC('05:15:40')");
while($row=mysql_fetch_array($result))
{
echo "<tr>";
echo "<td align='center' width='200'>" . $row["TIME_TO_SEC('05:15:40')"] . "</td>";
echo "</tr>";
}
echo "</table>";
?>
</body>
</html>
  

View the example in browser



We have compiled a number of MySQL Questions and Answers. Check and assess you MySQL skill by visiting those questions and answers.

<<PreviousNext>>