Such calculations may lead to unpredictable results because when a date is represented as a MySQL string, MySQL attempts to perform the string execution on only the first occurrence of the string. Number crunching. The following example will clarify it -
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)
The above is the detailed content of How do the addition, subtraction, multiplication, and division operators work with dates represented as MySQL strings?. For more information, please follow other related articles on the PHP Chinese website!