summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--mysql-test/r/func_time.result34
-rw-r--r--mysql-test/t/func_time.test32
-rw-r--r--sql/item_timefunc.cc2
3 files changed, 66 insertions, 2 deletions
diff --git a/mysql-test/r/func_time.result b/mysql-test/r/func_time.result
index d8ba606a558..d8797fd454b 100644
--- a/mysql-test/r/func_time.result
+++ b/mysql-test/r/func_time.result
@@ -695,3 +695,37 @@ t1 CREATE TABLE `t1` (
`from_unixtime(1) + 0` double(23,6) default NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1
drop table t1;
+SET @df:="%M %D, %Y";
+SELECT DATE_FORMAT('2005-10-31', "%M %D, %Y");
+DATE_FORMAT('2005-10-31', "%M %D, %Y")
+October 31st, 2005
+SELECT DATE_FORMAT('2005-10-31', @df);
+DATE_FORMAT('2005-10-31', @df)
+October 31st, 2005
+SELECT STR_TO_DATE('October 31st, 2005', "%M %D, %Y");
+STR_TO_DATE('October 31st, 2005', "%M %D, %Y")
+2005-10-31
+SELECT STR_TO_DATE('October 31st, 2005', @df);
+STR_TO_DATE('October 31st, 2005', @df)
+2005-10-31
+CREATE TABLE `dt` (
+d datetime,
+ds char(30)
+);
+INSERT INTO `dt` (d) VALUES ('2005-10-31'), ('2005-11-30');
+SET @df:="%M %D, %Y";
+UPDATE dt SET ds = DATE_FORMAT(d, @df);
+SELECT * FROM dt;
+d ds
+2005-10-31 00:00:00 October 31st, 2005
+2005-11-30 00:00:00 November 30th, 2005
+SELECT d, ds, STR_TO_DATE(ds, @df) FROM dt;
+d ds STR_TO_DATE(ds, @df)
+2005-10-31 00:00:00 October 31st, 2005 2005-10-31
+2005-11-30 00:00:00 November 30th, 2005 2005-11-30
+SELECT d, ds, STR_TO_DATE(ds, "%M %D, %Y") FROM dt;
+d ds STR_TO_DATE(ds, "%M %D, %Y")
+2005-10-31 00:00:00 October 31st, 2005 2005-10-31
+2005-11-30 00:00:00 November 30th, 2005 2005-11-30
+DROP TABLE `dt`;
+End of 4.1 tests
diff --git a/mysql-test/t/func_time.test b/mysql-test/t/func_time.test
index b8647a281d4..bf17efbd67e 100644
--- a/mysql-test/t/func_time.test
+++ b/mysql-test/t/func_time.test
@@ -368,4 +368,34 @@ create table t1 select now() - now(), curtime() - curtime(),
show create table t1;
drop table t1;
-# End of 4.1 tests
+
+
+#
+# Bug #20987: str_to_date doesn't accept user variable for specification
+#
+
+SET @df:="%M %D, %Y";
+SELECT DATE_FORMAT('2005-10-31', "%M %D, %Y");
+SELECT DATE_FORMAT('2005-10-31', @df);
+SELECT STR_TO_DATE('October 31st, 2005', "%M %D, %Y");
+SELECT STR_TO_DATE('October 31st, 2005', @df);
+
+CREATE TABLE `dt` (
+ d datetime,
+ ds char(30)
+);
+
+INSERT INTO `dt` (d) VALUES ('2005-10-31'), ('2005-11-30');
+SET @df:="%M %D, %Y";
+
+UPDATE dt SET ds = DATE_FORMAT(d, @df);
+
+SELECT * FROM dt;
+SELECT d, ds, STR_TO_DATE(ds, @df) FROM dt;
+SELECT d, ds, STR_TO_DATE(ds, "%M %D, %Y") FROM dt;
+
+DROP TABLE `dt`;
+
+
+
+--echo End of 4.1 tests
diff --git a/sql/item_timefunc.cc b/sql/item_timefunc.cc
index 44d9b422263..e3b71851824 100644
--- a/sql/item_timefunc.cc
+++ b/sql/item_timefunc.cc
@@ -223,7 +223,7 @@ static bool extract_date_time(DATE_TIME_FORMAT *format,
tmp= (char*) val + min(2, val_len);
l_time->day= (int) my_strtoll10(val, &tmp, &error);
/* Skip 'st, 'nd, 'th .. */
- val= tmp + min((int) (end-tmp), 2);
+ val= tmp + min((int) (val_end-tmp), 2);
break;
/* Hour */