此類運算可能會導致不可預測的結果,因為當日期表示為MySQL 字串時,MySQL 會嘗試只採用第一個出現的字串來對字串執行數字運算。以下範例將闡明它 -
mysql> select '2017-10-17' + 20; +-------------------+ | '2017-10-17' + 20 | +-------------------+ | 2037 | +-------------------+ 1 row in set, 1 warning (0.00 sec) mysql> select '2017-10-25' - 17; +-------------------+ | '2017-10-25' - 17 | +-------------------+ | 2000 | +-------------------+ 1 row in set, 1 warning (0.00 sec) mysql> select '2017-10-17' * 2; +-------------------+ | '2017-10-17' * 20 | +-------------------+ | 4034 | +-------------------+ 1 row in set, 1 warning (0.00 sec) mysql> select '2017-05-25'/5; +----------------+ | '2017-05-25'/5 | +----------------+ | 403.4 | +----------------+ 1 row in set, 1 warning (0.00 sec)
以上是加法、減法、乘法和除法運算子如何處理表示為 MySQL 字串的日期?的詳細內容。更多資訊請關注PHP中文網其他相關文章!