Home > Database > Mysql Tutorial > How to get the current time in mysql

How to get the current time in mysql

王林
Release: 2020-10-22 09:32:34
Original
34846 people have browsed it

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 |
+---------------------+
Copy after login

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 |
+---------------------+----------+---------------------+
Copy after login

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 |
+---------------------+---------------------+
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template