w3resource logo


MySQL CURTIME function

MySQL CURTIME() function

rating has average rating 10 out of 10. Total 1 users rated.

<<PreviousNext>>

Description

In MySQL the CURTIME() returns the value of current time in ‘HH:MM:SS’ format or HHMMSS.uuuuuu format depending on whether numeric or string is used in the function. CURRENT_TIME() and CURRENT_TIME are the synonym of CURTIME().

Note: All of the example codes of this page will produce outputs depending upon the current time.

Syntax

CURTIME();

Example :

Code

SELECT CURTIME();

Explanation

The above statement will return the current time in ‘HH:SS:MM’ format.

Output

MySQL CURTIME()

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>php mysql examples</title>
</head>
<body>
<?php
echo "<h2>Showing current time using MySQL : </h2>";
echo "<table border='1' style='border-collapse: collapse;border-color: silver;'>";
echo "<tr style='font-weight: bold;'>";
echo "<td width='100' align='center'>Current time</td>";
echo "</tr>";
include("../dbopen.php");
$result = mysql_query("SELECT CURTIME()");
while($row=mysql_fetch_array($result))
{
echo "<tr>";
echo "<td align='center' width='200'>" . $row['CURTIME()'] . "</td>";
echo "</tr>";
}
echo "</table>";
?>
</body>
</html>

View the example in browser

Example : CURTIME() function with numeric format

Code

SELECT CURTIME()+10;

Explanation

The above statement will return the current time in HHMMSS.uuuuuu format. Because the context of the function is numeric.

Output

MySQL CURTIME() EXAMPLE

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>php mysql examples</title>
</head>
<body>
<?php
echo "<h2>Showing current time in HHMMSS.uuuuuu  format using MySQL : </h2>";
echo "<table border='1' style='border-collapse: collapse;border-color: silver;'>";
echo "<tr style='font-weight: bold;'>";
echo "<td width='100' align='center'>Current time</td>";
echo "</tr>";
include("../dbopen.php");
$result = mysql_query("SELECT CURTIME()+10");
while($row=mysql_fetch_array($result))
{
echo "<tr>";
echo "<td align='center' width='200'>" . $row['CURTIME()+10'] . "</td>";
echo "</tr>";
}
echo "</table>";
?>
</body>
</html>

View the example in browser

photo credit: epSos.de. Photo is used under creative Common License.

<<PreviousNext>>