select*fromexample;+------------ +|orderdate |+------------+|2017-05-25|+------------+1rowinset(0.00sec)mysql>selectorderdate+10"/> select*fromexample;+------------ +|orderdate |+------------+|2017-05-25|+------------+1rowinset(0.00sec)mysql>selectorderdate+10">

Home  >  Article  >  Database  >  How do the addition, subtraction, multiplication and division operators work with date values ​​stored in MySQL tables?

How do the addition, subtraction, multiplication and division operators work with date values ​​stored in MySQL tables?

WBOY
WBOYforward
2023-09-16 16:25:021002browse

加法、减法、乘法和除法运算符如何处理 MySQL 表中存储的日期值?

When we try to do such operations on date values ​​stored in the table, MySQL assumes the date values ​​are numbers and performs arithmetic operations.

Suppose we have a table called "example" which has a date value in the "orderdate" column, then doing arithmetic will clarify the above -

mysql> select * from example;
+------------+
| orderdate  |
+------------+
| 2017-05-25 |
+------------+
1 row in set (0.00 sec)

mysql> select orderdate+10 from example;
+--------------+
| orderdate+10 |
+--------------+
|     20170535 |
+--------------+
1 row in set (0.00 sec)

mysql> select orderdate*10 from example;
+--------------+
| orderdate*10 |
+--------------+
|    201705250 |
+--------------+
1 row in set (0.00 sec)

mysql> select orderdate-10 from example;
+--------------+
| orderdate-10 |
+--------------+
|     20170515 |
+--------------+
1 row in set (0.00 sec)

mysql> select orderdate/10 from example;
+--------------+
| orderdate/10 |
+--------------+
|    2017052.5 |
+--------------+
1 row in set (0.00 sec)

The above is the detailed content of How do the addition, subtraction, multiplication and division operators work with date values ​​stored in MySQL tables?. 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