此类计算可能会导致不可预测的结果,因为当日期表示为 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中文网其他相关文章!