Home >Database >Mysql Tutorial >Current date and time functions in mysql
There are three functions in MySQL to obtain the current date and time: 1. NOW() function: returns the current date and time in the format of 'YYYY-MM-DD HH:MM:SS'; 2. CURDATE () Function: Returns the current date in the format of 'YYYY-MM-DD'; 3. CURTIME() Function: Returns the current time in the format of 'HH:MM:SS'.
Function to get the current date and time in MySQL
NOW() function
NOW() function returns the current date and time in the format of 'YYYY-MM-DD HH:MM:SS'.
Example:
<code class="sql">SELECT NOW();</code>
Result:
<code>2023-03-08 14:32:31</code>
CURDATE() function
CURDATE() function returns the current date in the format of 'YYYY-MM-DD'.
Example:
<code class="sql">SELECT CURDATE();</code>
Result:
<code>2023-03-08</code>
CURTIME() function
CURTIME() function returns the current time in the format of 'HH:MM:SS'.
Example:
<code class="sql">SELECT CURTIME();</code>
Result:
<code>14:32:31</code>
Other usage
In addition to using these functions alone, they can also be used in combination with other functions, such as:
Note:
These functions return the current date and time on the server, not the date and time on the client computer.
The above is the detailed content of Current date and time functions in mysql. For more information, please follow other related articles on the PHP Chinese website!