Home > Database > Mysql Tutorial > body text

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

WBOY
Release: 2023-09-16 20:53:02
forward
890 people have browsed it

加法、减法、乘法和除法运算符如何处理表示为 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)
Copy after login

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!

source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template