w3resource logo


MySQL LOCALTIMESTAMP function

MySql LOCALTIMESTAMP

<<PreviousNext>>

Description

MySQL LOCALTIMESTAMP returns the value of current date and time in ‘YYYY-MM-DD HH:MM:SS’ format or YYYMMDDHHMMSS.uuuuuu format depending on the context (numeric or string) of the function.

CURRENT_TIMESTAMP, CURRENT_TIMESTAMP(), NOW, NOW(), LOCALTIME, LOALTIME(), LOCALTIMESTAMP() are the synonyms of LOCALTIMESTAMP.

The LOCALTIMESTAMP 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

LOCALTIMESTAMP;

Example :

Code

SELECT LOCALTIMESTAMP;

Explanation

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

Output

MySQL LOCALTIMESTAMP

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>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 LOCALTIMESTAMP");
while($row=mysql_fetch_array($result))
{
echo "<tr>";
echo "<td align='center' width='200'>" . $row["LOCALTIMESTAMP"] . "</td>";
echo "</tr>";
}
echo "</table>";
?>
</body>
</html>

View the example in browser

Example : LOCALTIMESTAMP in numeric format

Code

SELECT LOCALTIMESTAMP,LOCALTIMESTAMP+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 LOCALTIMESTAMP 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>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='430' align='center'>Current date and time in YYYYMMDDHHSSMM.uuuuuu format</td>";
echo "</tr>";
include("../dbopen.php");
$result = mysql_query("SELECT LOCALTIMESTAMP,LOCALTIMESTAMP+1");
while($row=mysql_fetch_array($result))
{
echo "<tr>";
echo "<td align='center' width='200'>" . $row["LOCALTIMESTAMP"] . "</td>";
echo "<td align='center' width='200'>" . $row["LOCALTIMESTAMP+1"] . "</td>";
echo "</tr>";
}
echo "</table>";
?>
</body>
</html>

View the example in browser

Example : LOCALTIMESTAMP()

Code

SELECT LOCALTIMESTAMP();

Explanation

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

Output

MySQL LOCALTIMESTAMP()

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>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='430' align='center'>Current date and time in YYYYMMDDHHSSMM.uuuuuu format</td>";
echo "</tr>";
include("../dbopen.php");
$result = mysql_query("SELECT LOCALTIMESTAMP()");
while($row=mysql_fetch_array($result))
{
echo "<tr>";
echo "<td align='center' width='200'>" . $row["LOCALTIMESTAMP()"] . "</td>";
echo "</tr>";
}
echo "</table>";
?>
</body>
</html>

View the example in browser

Example : LOCALTIMESTAMP() in numeric format

Code

 SELECT LOCALTIMESTAMP(),LOCALTIMESTAMP()+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 LOCALTIMESTAMP() 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>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='430' align='center'>Current date and time in YYYYMMDDHHSSMM.uuuuuu format</td>";
echo "</tr>";
include("../dbopen.php");
$result = mysql_query("SELECT LOCALTIMESTAMP(),LOCALTIMESTAMP()+1");
while($row=mysql_fetch_array($result))
{
echo "<tr>";
echo "<td align='center' width='200'>" . $row["LOCALTIMESTAMP"] . "</td>";
echo "<td align='center' width='200'>" . $row["LOCALTIMESTAMP+1"] . "</td>";
echo "</tr>";
}
echo "</table>";
?>
</body>
</html>

View the example in browser

photo credit: Gerard Stolk. Photo is used under creative Common License.

<<PreviousNext>>