Bug #631 curdate has problems outside actual maonth
Submitted: 11 Jun 2003 2:59 Modified: 11 Jun 2003 3:50
Reporter: cedric boudin Email Updates:
Status: Not a Bug Impact on me:
None 
Category:MySQL Server Severity:S3 (Non-critical)
Version: 3.23.49-8.4 OS:Linux (debian woody i386)
Assigned to: CPU Architecture:Any

[11 Jun 2003 2:59] cedric boudin
Description:
It is allways a problem is it feature or a bug :=)
cheers

mysql> select curdate() ;   
+------------+
| curdate()  |
+------------+
| 2003-06-11 |
+------------+
1 row in set (0.01 sec)

mysql> select curdate() -12;
+---------------+
| curdate() -12 |
+---------------+
|      20030599 |
+---------------+
1 row in set (0.00 sec)

mysql> select curdate() +25;
+---------------+
| curdate() +25 |
+---------------+
|      20030636 |
+---------------+
1 row in set (0.00 sec)

How to repeat:
there is not much to tell about repeating it !!

Suggested fix:
I du not know
[11 Jun 2003 3:01] cedric boudin
I had a look at the docum 
nothing was described here about a limitation
[11 Jun 2003 3:50] Alexander Keremidarski
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.mysql.com/documentation/ and the instructions on
how to report a bug at http://bugs.mysql.com/how-to-report.php

Result you get i correct and docummented.

SELECT CURDATE() - 12;

Works as following:

'-' expects two numeric operands.
Right operand is INTEGER that's why left one is converted to INTEGER too.
which means CURDATE() result '2003-06-11' is converted according to date->int rules and becomes 20030611

Wo what you are doing is to subtract 12 from above INTEGER and result you get is 100% correct

20030611 - 12 = 20030599

There are functions for date/time calculations. If you want to subtract 12 days/seconds/years+seconds/whatever date or time interval you must use well docummented DATE_SUB() function or it's alternative syntax:

mysql> SELECT CURDATE(), CURDATE() - INTERVAL 12 DAY;
+------------+-----------------------------+
| CURDATE()  | CURDATE() - INTERVAL 12 DAY |
+------------+-----------------------------+
| 2003-06-11 | 2003-05-30                  |
+------------+-----------------------------+
[11 Jun 2003 4:46] cedric boudin
thanks for the info
as usual I should have RTFM
thoroughly