可以将TIME(N)和DATETIME(N)值转换为数字形式,方法是将它们添加0(+0)。以下是这种转换的规则-
当N为0时,TIME(N)和DATETIME(N)值将转换为整数。
例如,值CURTIME()
和NOW()
可以转换为整数值如下-
mysql> SELECT CURTIME(), CURTIME()+0; +-----------+-------------------+ | CURTIME() | CURTIME()+0 | +-----------+-------------------+ | 19:42:54 | 194254 | +-----------+-------------------+ 1 row in set (0.04 sec) mysql> SELECT NOW(), NOW()+0; +-------------------------+----------------------------------+ | NOW() | NOW()+0 | +-------------------------+----------------------------------+ | 2017-10-27 19:43:43 | 20171027194343 | +-------------------------+----------------------------------+ 1 row in set (0.00 sec)
的时间(N)和DATETIME(N)的值将被转换为整数时,N是大于0
例如,的值CURTIME()
和NOW()
可如下转化成十进制值-
mysql> SELECT CURTIME(), CURTIME(3)+0; +-----------+-------------------+ | CURTIME() | CURTIME()+0 | +-----------+-------------------+ | 19:47:40 | 194740.575 | +-----------+-------------------+ 1 row in set (0.04 sec) mysql> SELECT NOW(), NOW(3)+0; +-------------------------+----------------------------------+ | NOW() | NOW()+0 | +-------------------------+----------------------------------+ | 2017-10-27 19:48:45 | 20171027194845.589 | +-------------------------+----------------------------------+ 1 row in set (0.00 sec)