Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Date Arithmetic Operations in MySQL



When we try to do such kind of operations with date values stored in the table then MySQL is assuming the date values as the number and perform the arithmetic.

Suppose we have a table named ‘example’ having a date value in ‘orderdate’ column then following arithmetic operation 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)
Updated on: 2020-01-28T11:01:22+05:30

159 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements