w3resource logo


MySQL LOCALTIME function

MySql LOCALTIME

<<PreviousNext>>

Description

MySQL LOCALTIME returns the value of current date and time in ‘YYYY-MM-DD HH:MM:SS’ format or YYYYMMDDHHMMSS.uuuuuu format depending on the context (numeric or string) of the function. CURRENT_TIMESTAMP, CURRENT_TIMESTAMP(), NOW, NOW(), LOCALTIME(), LOALTIMESTAMP, LOCALTIMESTAMP() are the synonyms of LOCALTIME. The LOCALTIME returns the constant time when the statement began to work.

Note : Output of the examples of this page will depend upon the current time.

Syntax

LOCALTIME;


Example : LOCALTIME

Code

SELECT LOCALTIME;

Explanation

The above statement will return the current date and time in ‘YYYY-MM-DD HH:SS:MM’ format.

Output

MySQL LOCALTIME

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-LOCALTIME-function - php mysql examples | w3resource</title>
</head>
<body>
<?php
echo "<h2>Displaying current date and time in YYYY-MM-DD HH:SS:MM format : </h2>";
echo "<table border='1' style='border-collapse: collapse;border-color: silver;'>";
echo "<tr style='font-weight: bold;'>";
echo "<td width='300' align='center'>Current date and time in YYYY-MM-DD HH:SS:MM format</td>";
echo "</tr>";
include("../dbopen.php");
$result = mysql_query("SELECT LOCALTIME");
while($row=mysql_fetch_array($result))
{
echo "<tr>";
echo "<td align='center' width='200'>" . $row["LOCALTIME"] . "</td>";
echo "</tr>";
}
echo "</table>";
?>
</body>
</html>

View the example in browser

Example : LOCALTIME in numeric format

Code

SELECT LOCALTIME,LOCALTIME+1;

Explanation

The above statement will return the current date and time in ‘YYYY-MM-DD HH:SS:MM’ format as well as YYYYMMDDHHSSMM.uuuuuu format.

Output

MySQL LOCALTIME 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>example1-LOCALTIME-function - php mysql examples | w3resource</title>
</head>
<body>
<?php
echo "<h2>Displaying current date and time in YYYY-MM-DD HH:SS:MM format as well as in YYYYMMDDHHSSMM.uuuuuu format : </h2>";
echo "<table border='1' style='border-collapse: collapse;border-color: silver;'>";
echo "<tr style='font-weight: bold;'>";
echo "<td width='300' align='center'>current date and time in YYYY-MM-DD HH:SS:MM format</td><td width='300' align='center'>current date and time in YYYYMMDDHHSSMM.uuuuuu format</td>";
echo "</tr>";
include("../dbopen.php");
$result = mysql_query("SELECT LOCALTIME,LOCALTIME+1");
while($row=mysql_fetch_array($result))
{
echo "<tr>";
echo "<td align='center' width='200'>" . $row["LOCALTIME"] . "</td>";
echo "<td align='center' width='200'>" . $row["LOCALTIME+1"] . "</td>";
echo "</tr>";
}
echo "</table>";
?>
</body>
</html>
 

View the example in browser

Example : LOCALTIME()

Code

SELECT LOCALTIME();

Explanation

The above statement will return the current date and time in ‘YYYY-MM-DD HH:SS:MM’ format.

Output

MySQL localtime()

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>example2-LOCALTIME-function - php mysql examples | w3resource</title>
</head>
<body>
<?php
echo "<h2>Displaying current date and time in YYYY-MM-DD HH:SS:MM format : </h2>";
echo "<table border='1' style='border-collapse: collapse;border-color: silver;'>";
echo "<tr style='font-weight: bold;'>";
echo "<td width='430' align='center'>Current date and time in YYYY-MM-DD HH:SS:MM format</td>";
echo "</tr>";
include("../dbopen.php");
$result = mysql_query("SELECT LOCALTIME()");
while($row=mysql_fetch_array($result))
{
echo "<tr>";
echo "<td align='center' width='200'>" . $row["LOCALTIME()"] . "</td>";
echo "</tr>"; } echo "</table>"; ?> </body> </html>

View the example in browser

Example : LOCALTIME() in numeric format

Code

SELECT LOCALTIME(),LOCALTIME()+1;

Explanation

The above statement will return the current date and time in ‘YYYY-MM-DD HH:SS:MM’ format as well as YYYYMMDDHHSSMM.uuuuuu format.

Output

MySQL LOCALTIME() 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>example3-LOCALTIME-function - php mysql examples | w3resource</title>
</head> <body> <?php echo "<h2>Displaying current date and time in YYYY-MM-DD HH:SS:MM format as well as in YYYYMMDDHHSSMM.uuuuuu format : </h2>"; echo "<table border='1' style='border-collapse: collapse;border-color: silver;'>"; echo "<tr style='font-weight: bold;'>"; echo "<td width='430' align='center'>Current date and time in YYYY-MM-DD HH:SS:MM format</td> <td width='470' align='center'>Current date and time in YYYYMMDDHHSSMM.uuuuuu format</td>"; echo "</tr>"; include("../dbopen.php"); $result = mysql_query("SELECT LOCALTIME(),LOCALTIME()+1"); while($row=mysql_fetch_array($result)) { echo "<tr>"; echo "<td align='center' width='200'>" . $row["LOCALTIME()"] . "</td>"; echo "<td align='center' width='200'>" . $row["LOCALTIME()+1"] . "</td>"; echo "</tr>"; } echo "</table>"; ?> </body> </html>

View the example in browser

photo credit: brizzle born and bred. Photo is used under creative Common License.

<<PreviousNext>>