Bug #42934 | Function current_date returns an invalid date. | ||
---|---|---|---|
Submitted: | 17 Feb 2009 15:05 | Modified: | 17 Feb 2009 22:19 |
Reporter: | Ed Singleton | Email Updates: | |
Status: | Not a Bug | Impact on me: | |
Category: | MySQL Server: DML | Severity: | S3 (Non-critical) |
Version: | 5.0.41 | OS: | Windows (2003) |
Assigned to: | CPU Architecture: | Any |
[17 Feb 2009 15:05]
Ed Singleton
[17 Feb 2009 16:33]
Valeriy Kravchuk
This is not a bug. When you subtract integer from date you subtract integers. Look: valeriy-kravchuks-macbook-pro:5.0 openxs$ bin/mysql -uroot test Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 1 Server version: 5.0.79-debug Source distribution Type 'help;' or '\h' for help. Type '\c' to clear the buffer. mysql> select current_date(); +----------------+ | current_date() | +----------------+ | 2009-02-17 | +----------------+ 1 row in set (0.00 sec) mysql> select current_date() - 30; +---------------------+ | current_date() - 30 | +---------------------+ | 20090187 | +---------------------+ 1 row in set (0.00 sec) So, date was implicitly converted to integer and the result may be not a valid date when converted back to date. This is how to do this correctly: mysql> select current_date() - interval 30 day; +----------------------------------+ | current_date() - interval 30 day | +----------------------------------+ | 2009-01-18 | +----------------------------------+ 1 row in set (0.00 sec)
[17 Feb 2009 22:19]
Ed Singleton
Thanks for the info Valeriy. Our bad. The user may not have noticed the warning in the past as the query usually returned results. The function must assume the intent of '- 30' was '- interval 30 day'.