hi,欢迎访问本站!
当前位置: 首页数据库正文

mysql中常用的时间日期函数

墨初 数据库 273阅读

在mysql语句中有几个常用的获取时间日期的函数,比如 current_time,current,current_data,now等,下面是这些函数的介绍以及用法。

mysql current_time

mysql 中的 current_time 函数可以获取当前的时间,并以 hh:ii:ss 格式进行输出。

语句格式:

select current_time;

select current_time();

例:

mysql> select current_time;
+--------------+
| current_time |
+--------------+
| 15:14:28     |
+--------------+
1 row in set (0.00 sec)
mysql> select current_time();
+----------------+
| current_time() |
+----------------+
| 15:14:39       |
+----------------+
1 row in set (0.00 sec)

mysql current_date

mysql 中的 current_date 函数可以获取当前的日期,并以 yyyy-mm-dd 格式进行输出。

语句格式:

select current_date;

select current_date();

例:

mysql> select current_date;
+--------------+
| current_date |
+--------------+
| 2023-01-06   |
+--------------+
1 row in set (0.00 sec)
mysql> select current_date();
+----------------+
| current_date() |
+----------------+
| 2023-01-06     |
+----------------+
1 row in set (0.00 sec)

mysql current_timestamp

mysql current_timestamp 函数可以获取当前的日期与时间,并以 yyyy-mm-dd hh:ii:ss 的格式输出。

语句格式:

select current_timestamp;

select current_timestamp();

例:

mysql> select current_timestamp;
+---------------------+
| current_timestamp   |
+---------------------+
| 2023-01-06 15:18:36 |
+---------------------+
1 row in set (0.00 sec)
mysql> select current_timestamp();
+---------------------+
| current_timestamp() |
+---------------------+
| 2023-01-06 15:18:42 |
+---------------------+
1 row in set (0.00 sec)

mysql now()

mysql 中的 now() 函数,可以获取当前的日期与时间。

例:

mysql> select now();
+---------------------+
| now()               |
+---------------------+
| 2023-01-06 15:20:35 |
+---------------------+
1 row in set (0.00 sec)

mysql curdate()

mysql 中的 curdate() 函数可以获取当前的日期!

例:

mysql> select curdate();
+------------+
| curdate()  |
+------------+
| 2023-01-06 |
+------------+
1 row in set (0.00 sec)

mysql curtime()

mysql 中的 curtime() 函数可以获取当前时间。

例:

mysql> select curtime();
+-----------+
| curtime() |
+-----------+
| 15:22:59  |
+-----------+
1 row in set (0.00 sec)
标签:
声明:无特别说明,转载请标明本文来源!