MySQL:unix_timestamp() 函数


#MySQL 笔记


unix_timestamp 函数可以将日期时间转换为 unix 时间戳。

SQL 执行结果
select unix_timestamp('2019-01-05 22:29:36'); 1546698576
select unix_timestamp('2019-01-05 00:00:00'); 1546617600
select unix_timestamp('2019-01-05'); 1546617600
select unix_timestamp('2019/01/05'); 1546617600
select unix_timestamp(now()); 当前的时间戳, 如 1586576346
select unix_timestamp(); 当前的时间戳, 如 1586576346

限制:unix_timestamp 能处理的时间上限是 int 最大值 2147483647 对应的时间 2038-01-19 11:14:07。超出后,会处理成 0 。

mysql> select unix_timestamp('2038-01-19 11:14:07');
+---------------------------------------+
| unix_timestamp('2038-01-19 11:14:07') |
+---------------------------------------+
| 2147483647                            |
+---------------------------------------+

mysql> select unix_timestamp('2038-01-19 11:14:08');
+---------------------------------------+
| unix_timestamp('2038-01-19 11:14:08') |
+---------------------------------------+
| 0                                     |
+---------------------------------------+


( 本文完 )