Home  >  Article  >  Database  >  How do the addition, subtraction, multiplication, and division operators work with dates represented as MySQL strings?

How do the addition, subtraction, multiplication, and division operators work with dates represented as MySQL strings?

WBOY
WBOYforward
2023-09-16 20:53:02885browse

加法、减法、乘法和除法运算符如何处理表示为 MySQL 字符串的日期?

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!

Statement:
This article is reproduced at:tutorialspoint.com. If there is any infringement, please contact admin@php.cn delete