CURRENT_TIMESTAMP()

函数说明

CURRENT_TIMESTAMPCURRENT_TIMESTAMP()NOW() 的同义词。

将当前日期和时间以 YYYY-MM-DD hh:mm:ssYYYYMMDDhhmmss 的格式返回,返回格式取决于函数是字符串还是数字。取值为当前会话所在的时区。

函数语法

  1. > CURRENT_TIMESTAMP([fsp])

参数释义

参数说明
fsp可选。参数 fsp 参数用于指定分秒精度,有效值为 0 到 6 之间的整数。

示例

  1. mysql> SELECT CURRENT_TIMESTAMP();
  2. +----------------------------+
  3. | current_timestamp() |
  4. +----------------------------+
  5. | 2022-09-21 11:46:44.153777 |
  6. +----------------------------+
  7. 1 row in set (0.00 sec)
  8. mysql> SELECT NOW();
  9. +----------------------------+
  10. | now() |
  11. +----------------------------+
  12. | 2022-09-21 12:56:36.915961 |
  13. +----------------------------+
  14. 1 row in set (0.01 sec)
  1. create table t1 (a int primary key, b int, c int, d timestamp default current_timestamp);
  2. insert into t1 select 1,1,1,now();
  3. insert into t1 select 2,0,0,null;
  4. mysql> select a,b,c,year(d) from t1;
  5. +------+------+------+---------+
  6. | a | b | c | year(d) |
  7. +------+------+------+---------+
  8. | 1 | 1 | 1 | 2022 |
  9. | 2 | 0 | 0 | NULL |
  10. +------+------+------+---------+
  11. 2 rows in set (0.01 sec)

限制

运算符 +- 现在不支持与 CURRENT_TIMESTAMP 一起使用。