众所周知,借助UNIX_TIMESTAMP()函数,可以将timestamp的值转换为秒数。MySQL将忽略添加到timestamp值中的微秒,因为UNIX_TIMESTAMP的值只有10位数字。
mysql> SELECT UNIX_TIMESTAMP('2017-10-22 04:05:36')AS 'Total Number of Seconds'; +-------------------------+ | Total Number of Seconds | +-------------------------+ | 1508625336 | +-------------------------+ 1 row in set (0.00 sec) mysql> SELECT UNIX_TIMESTAMP('2017-10-22 04:05:36.200000')AS 'Total Number of Seconds'; +-------------------------+ | Total Number of Seconds | +-------------------------+ | 1508625336 | +-------------------------+ 1 row in set (0.00 sec)
上面的查询显示,即使将6位数的微秒值相加,输出仍然保持不变。