1、获取当前日期函数
CURDATE()
CURRENT_DATE()
函数获取当前日期,将当前日期按照'YYYY-MM-DD' 或 YYYYMMDD 格式返回
mysql> SELECT CURDATE(), CURRENT_DATE(), CURDATE()+0;
+------------+----------------+-------------+
| CURDATE() | CURRENT_DATE() | CURDATE()+0 |
+------------+----------------+-------------+
| 2021-12-04 | 2021-12-04 | 20211204 |
+------------+----------------+-------------+
2、获取当前时间
CURTIME() 和
CURRENT_TIME()
函数获取当前时间,将当前时间以'HH:MM:SS' 或 HHMMSS的格式返回
mysql> SELECT CURTIME(), CURRENT_TIME(), CURTIME()+0;
+-----------+----------------+-------------+
| CURTIME() | CURRENT_TIME() | CURTIME()+0 |
+-----------+----------------+-------------+
| 18:17:35 | 18:17:35 | 181735 |
+-----------+----------------+-------------+
3、获取当前日期加时间
NOW();
SYSDATE();
LOCALTIME();
CURRENT_TIMESTAMP();
这4个函数都可以返回当前日期和时间。
mysql> SELECT NOW(),SYSDATE(),LOCALTIME(),CURRENT_TIMESTAMP();
+---------------------+---------------------+---------------------+---------------------+
| NOW() | SYSDATE() | LOCALTIME() | CURRENT_TIMESTAMP() |
+---------------------+---------------------+---------------------+---------------------+
| 2021-12-04 18:22:42 | 2021-12-04 18:22:42 | 2021-12-04 18:22:42 | 2021-12-04 18:22:42 |
+---------------------+---------------------+---------------------+---------------------+