Home >Database >Mysql Tutorial >Current date and time functions in mysql

Current date and time functions in mysql

下次还敢
下次还敢Original
2024-04-29 03:45:21814browse

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'.

Current date and time functions in mysql

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:

  • DATE_ADD(): Add the specified number of days or time to the current date or time.
  • DATE_SUB(): Subtract the specified number of days or time from the current date or time.
  • DATE_FORMAT(): Convert a date or time to a different format.

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:How to use like in mysqlNext article:How to use like in mysql