Bug #61193 incorrect rounding of date DECIMAL(17,3)
Submitted: 16 May 2011 22:49 Modified: 1 Jun 2011 15:38
Reporter: leo strashnoy Email Updates:
Status: Verified Impact on me:
None 
Category:MySQL Server: Data Types Severity:S3 (Non-critical)
Version:5.1.58, 5.5 OS:Any
Assigned to: CPU Architecture:Any
Tags: 3), date DECIMAL(17

[16 May 2011 22:49] leo strashnoy
Description:
select time(20110512154559.616), 
date(20110512154559.616), 
date(floor(20110512154559.616));

returns:
15:45:59.6160000	null	5/12/2011 12:00:00 AM

How to repeat:
select time(20110512154559.616), 
date(20110512154559.616), 
date(floor(20110512154559.616));
[17 May 2011 3:15] Valeriy Kravchuk
Verified with 5.1.58 on Mac:

macbook-pro:5.1 openxs$ bin/mysql -uroot -P3306 --host=127.0.0.1 test
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 9
Server version: 5.1.58-debug Source distribution

Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.
This software comes with ABSOLUTELY NO WARRANTY. This is free software,
and you are welcome to modify and redistribute it under the GPL v2 license

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> select time(20110512154559.616), 
    -> date(20110512154559.616), 
    -> date(floor(20110512154559.616));
+--------------------------+--------------------------+---------------------------------+
| time(20110512154559.616) | date(20110512154559.616) | date(floor(20110512154559.616)) |
+--------------------------+--------------------------+---------------------------------+
| 15:45:59.616000          | NULL                     | 2011-05-12                      |
+--------------------------+--------------------------+---------------------------------+
1 row in set, 1 warning (0.08 sec)

mysql> show warnings\G
*************************** 1. row ***************************
  Level: Warning
   Code: 1292
Message: Incorrect datetime value: '20110512154560'
1 row in set (0.02 sec)

Looks inconsistent (time() vs date() behavior) and, thus, a bug.
[17 May 2011 15:57] leo strashnoy
The problem is the rounding for the dates. I hope you have a patch for that.
Meanwhile can I overload function like this:

CREATE FUNCTION test.date(p1 decimal(17,3)) RETURNS date 
NO SQL  RETURN  date(floor(p1)) ;