Bug #79827 Calculating the date different in 2 different ways produces differing results
Submitted: 3 Jan 2016 11:48 Modified: 29 Feb 2016 12:49
Reporter: Alex Blundell Email Updates:
Status: No Feedback Impact on me:
None 
Category:MySQL Server Severity:S3 (Non-critical)
Version:5.5.46-cll OS:CentOS (CentOS release 6.7)
Assigned to: CPU Architecture:Any
Tags: date

[3 Jan 2016 11:48] Alex Blundell
Description:
After the turn of the new year, an existing SQL statement to retrieve a list of rows within a given date stopped working correctly. The statement in question is:

SELECT COUNT(*) AS cnt FROM entries WHERE type = 'xxxxx' AND email = 'xx@xxx.com' AND date_created >= CURRENT_DATE-'30 days'

Once this was changed to the following statement, the correct behaviour happened:

SELECT COUNT(*) AS cnt FROM entries WHERE type = 'xxxxx' AND email = 'xx@xxx.com' AND date_created >= DATE_SUB(CURRENT_DATE, INTERVAL 30 DAY)

How to repeat:
Running the above 2 SQL statements will produce different results, even though they should produce the same result on the following table.

CREATE TABLE `entries` (
  `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
  `type` varchar(30) DEFAULT NULL,
  `email` varchar(255) DEFAULT NULL,
  `date_created` datetime DEFAULT NULL,
  `date_updated` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM AUTO_INCREMENT=4466 DEFAULT CHARSET=latin1;

Suggested fix:
N/A
[29 Jan 2016 12:49] MySQL Verification Team
Please provide a dump file to insert data, the result you get and the expected one. Thanks.
[1 Mar 2016 1:00] Bugs System
No feedback was provided for this bug for over a month, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to "Open".