select*fromexample;+------------ +|orderdate |+------------+|2017-05-25|+------------+1rowinset(0.00sec)mysql>selectorderdate+10"/> select*fromexample;+------------ +|orderdate |+------------+|2017-05-25|+------------+1rowinset(0.00sec)mysql>selectorderdate+10">
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!