存储在 MySQL 表中的日期值将如何使用加法、减法、乘法和除法运算符?
当我们尝试对存储在表中的日期值执行此类操作时,MySQL 会将日期值视为数值并执行算术运算。
假设我们有一个名为“example”的表,其中“orderdate”列有日期值,那么以下算术运算将阐明上述情况 −
mysql> select * from example; +------------+ | orderdate | +------------+ | 2017-05-25 | +------------+ 1 row in set (0.00 sec) mysql> select orderdate+10 from example; +--------------+ | orderdate+10 | +--------------+ | 20170535 | +--------------+ 1 row in set (0.00 sec) mysql> select orderdate*10 from example; +--------------+ | orderdate*10 | +--------------+ | 201705250 | +--------------+ 1 row in set (0.00 sec) mysql> select orderdate-10 from example; +--------------+ | orderdate-10 | +--------------+ | 20170515 | +--------------+ 1 row in set (0.00 sec) mysql> select orderdate/10 from example; +--------------+ | orderdate/10 | +--------------+ | 2017052.5 | +--------------+ 1 row in set (0.00 sec)
广告