Bug #6914 problems using time() / date() output in expressions
Submitted: 1 Dec 2004 12:26 Modified: 30 Dec 2004 17:45
Reporter: Axel Schwenke Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server Severity:S2 (Serious)
Version:4.1.7 OS:Linux (Linux)
Assigned to: Dmitry Lenev CPU Architecture:Any

[1 Dec 2004 12:26] Axel Schwenke
Description:
When using the date() or time() function to extract part of a DATETIME value and then using those results in ADDTIME(), SUBTIME() etc. expressions, I get wrong results.

How to repeat:
~ $mysql test
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2 to server version: 4.1.7-log

mysql> set @x=now();
Query OK, 0 rows affected (0,00 sec)

mysql> select @x, time(@x), subtime(@x, time(@x));
+---------------------+----------+-----------------------+
| @x                  | time(@x) | subtime(@x, time(@x)) |
+---------------------+----------+-----------------------+
| 2004-12-01 13:02:19 | 13:02:19 | 2004-11-30 00:00:00   |
+---------------------+----------+-----------------------+
1 row in set (0,00 sec)
==> Error: the subtime(...) result is off by one day; however

mysql> select @x, time(@x), subtime(@x, "13:02:19");
+---------------------+----------+-------------------------+
| @x                  | time(@x) | subtime(@x, "13:02:19") |
+---------------------+----------+-------------------------+
| 2004-12-01 13:02:19 | 13:02:19 | 2004-12-01 00:00:00     |
+---------------------+----------+-------------------------+
1 row in set (0,00 sec)
==> using a literal instead of time(...) works

mysql> select @x, date(@x), date(@x) + interval "01:00:00" hour_second;
+---------------------+------------+--------------------------------------------+
| @x                  | date(@x)   | date(@x) + interval "01:00:00" hour_second |
+---------------------+------------+--------------------------------------------+
| 2004-12-01 13:02:19 | 2004-12-01 | 2004-12-01 14:02:19                        |
+---------------------+------------+--------------------------------------------+
1 row in set (0,00 sec)
==> Error: the 3rd column should give "2004-12-01 01:00:00"
[1 Dec 2004 13:34] MySQL Verification Team
Verified with 4.1.8
[30 Dec 2004 17:45] Dmitry Lenev
Thank you for your bug report. This issue has been committed to our
source repository of that product and will be incorporated into the
next release.

If necessary, you can access the source repository and build the latest
available version, including the bugfix, yourself. More information 
about accessing the source trees is available at
    http://www.mysql.com/doc/en/Installing_source_tree.html

Additional info:

ChangeSet
  1.2161 04/12/30 13:39:01 dlenev@brandersnatch.localdomain +3 -0
  Fix for bug #6914 "Problems using time()/date() output in expressions".