MySQL 获得当前日期时间 函数
获得当前日期+时间(date + time)函数:now()mysql> select now();
+---------------------+
| now() |
+---------------------+
| 2021-12-16 13:59:56 |
+---------------------+
1 row in set (0.00 sec)
获得当前日期+时间(date + time)函数:sysdate()
sysdate() 日期时间函数跟 now() 类似,不同之处在于:now() 在执行开始时值就得到了, sysdate() 在函数执行时动态得到值。
mysql> select sysdate();
+---------------------+
| sysdate() |
+---------------------+
| 2021-12-16 14:00:03 |
+---------------------+
1 row in set (0.00 sec)
mysql> select now(),sleep(3),sysdate();
+---------------------+----------+---------------------+
| now() | sleep(3) | sysdate() |
+---------------------+----------+---------------------+
| 2021-12-16 14:00:30 | 0 | 2021-12-16 14:00:33 |
+---------------------+----------+---------------------+
1 row in set (3.00 sec)
MySQL 获得当前时间戳函数:current_timestamp, current_timestamp()
mysql> select current_timestamp, current_timestamp();
+---------------------+---------------------+
| current_timestamp | current_timestamp() |
+---------------------+---------------------+
| 2021-12-16 14:02:32 | 2021-12-16 14:02:32 |
+---------------------+---------------------+
1 row in set (0.00 sec)
页:
[1]