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

MySQL Operators with Date Represented as String



Such kind of calculations can cause unpredictable result because when the date is represented as MySQL string then MySQL tries to perform numeric operations on a string by taking only the first that appears. Following examples 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)
Updated on: 2020-01-28T10:40:17+05:30

209 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements