w3resource logo


MySQL SYSDATE function

MySQL SYSDATE() function

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

<<PreviousNext>>

Description

MySQL SYSDATE() returns the current date and time in YYYY-MM-DD HH:MM:SS or YYYYMMDDHHMMSS.uuuuuu format depending on the context of the function.

Note : For example codes using SYSDATE(), your output may vary form the output shown.

Syntax

SELECT SYSDATE()

Example :

The following statement will return current date and time.

SELECT SYSDATE();

Output

MySQL SYSDATE()

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-SYSDATE-function - php mysql examples | w3resource</title>
</head>
<body>
<?php
echo "<h2>Display current date and time : </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 datetime</td>";
echo "</tr>";
include("../dbopen.php");
$result = mysql_query("SELECT SYSDATE()");
while($row=mysql_fetch_array($result))
{
echo "<tr>";
echo "<td align='center' width='200'>" . $row["SYSDATE()"] . "</td>";
echo "</tr>";
}
echo "</table>";
?>
</body>
</html>

View the example in browser

Example : SYSDATE() function in numeric format

The following statement will return current date and time in numeric format.

SELECT SYSDATE()+0;

Output

MySQL SYSDATE() 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-SYSDATE-function - php mysql examples | w3resource</title>
</head>
<body>
<?php
echo "<h2>Display current datetime in numeric 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 datetime in numeric format</td>"; echo "</tr>"; include("../dbopen.php"); $result = mysql_query("SELECT SYSDATE()+0"); while($row=mysql_fetch_array($result)) { echo "<tr>"; echo "<td align='center' width='200'>" . $row['SYSDATE()+0'] . "</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>>