Home  >  Article  >  Database  >  How to get the current time in mysql

How to get the current time in mysql

王林
王林Original
2020-10-22 09:32:3434752browse

Mysql method to get the current time: You can get the current time by executing the [select now();] statement. It can also be obtained by executing the [select current_timestamp, current_timestamp();] statement.

How to get the current time in mysql

Get the current date and time (date time) function: now()

(Recommended tutorial: mysql video tutorial )

mysql> select now();

+---------------------+
| now() |
+---------------------+
| 2008-08-08 22:20:46 |
+---------------------+

Get the current date and time (date time) function: sysdate()

sysdate() The date and time function is similar to now(), except that now() starts at the beginning of execution The time value is obtained, and sysdate() obtains the value dynamically when the function is executed. Look at the following example to understand:

mysql> select now(), sleep(3), now();

+---------------------+----------+---------------------+
| now() | sleep(3) | now() |
+---------------------+----------+---------------------+
| 2008-08-08 22:28:21 | 0 | 2008-08-08 22:28:21 |
+---------------------+----------+---------------------+

MySQL Get the current timestamp function: current_timestamp, current_timestamp()

mysql> select current_timestamp, current_timestamp();

+---------------------+---------------------+
| current_timestamp | current_timestamp() |
+---------------------+---------------------+
| 2008-08-09 23:22:24 | 2008-08-09 23:22:24 |
+---------------------+---------------------+

Related recommendations: mysql tutorial

The above is the detailed content of How to get the current time 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