當我們嘗試對錶中儲存的日期值進行此類操作時,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)
以上是加法、減法、乘法和除法運算子如何處理 MySQL 表中儲存的日期值?的詳細內容。更多資訊請關注PHP中文網其他相關文章!