func_time.result 106 KB
Newer Older
1
drop table if exists t1,t2,t3;
2
set time_zone="+03:00";
3
select from_days(to_days("960101")),to_days(960201)-to_days("19960101"),to_days(date_add(curdate(), interval 1 day))-to_days(curdate()),weekday("1997-11-29");
4 5
from_days(to_days("960101"))	to_days(960201)-to_days("19960101")	to_days(date_add(curdate(), interval 1 day))-to_days(curdate())	weekday("1997-11-29")
1996-01-01	31	1	5
6
select period_add("9602",-12),period_diff(199505,"9404") ;
7 8
period_add("9602",-12)	period_diff(199505,"9404")
199502	13
9
select now()-now(),weekday(curdate())-weekday(now()),unix_timestamp()-unix_timestamp(now());
10
now()-now()	weekday(curdate())-weekday(now())	unix_timestamp()-unix_timestamp(now())
11
0	0	0
12
select from_unixtime(unix_timestamp("1994-03-02 10:11:12")),from_unixtime(unix_timestamp("1994-03-02 10:11:12"),"%Y-%m-%d %h:%i:%s"),from_unixtime(unix_timestamp("1994-03-02 10:11:12"))+0;
13
from_unixtime(unix_timestamp("1994-03-02 10:11:12"))	from_unixtime(unix_timestamp("1994-03-02 10:11:12"),"%Y-%m-%d %h:%i:%s")	from_unixtime(unix_timestamp("1994-03-02 10:11:12"))+0
14
1994-03-02 10:11:12	1994-03-02 10:11:12	19940302101112
15 16
select sec_to_time(9001),sec_to_time(9001)+0,time_to_sec("15:12:22"),
sec_to_time(time_to_sec("0:30:47")/6.21);
17
sec_to_time(9001)	sec_to_time(9001)+0	time_to_sec("15:12:22")	sec_to_time(time_to_sec("0:30:47")/6.21)
18
02:30:01	23001	54742	00:04:57.4235
Sergei Golubchik's avatar
Sergei Golubchik committed
19 20 21
select sec_to_time(9001.1), time_to_sec('15:12:22.123456'), time_to_sec(15.5566778899);
sec_to_time(9001.1)	time_to_sec('15:12:22.123456')	time_to_sec(15.5566778899)
02:30:01.1	54742.123456	15.556677
22 23
select sec_to_time(time_to_sec('-838:59:59'));
sec_to_time(time_to_sec('-838:59:59'))
24
-838:59:59
25 26 27 28 29
select sec_to_time('9001.1'), sec_to_time('1234567890123.123');
sec_to_time('9001.1')	sec_to_time('1234567890123.123')
02:30:01.100000	838:59:59.999999
Warnings:
Warning	1292	Truncated incorrect time value: '1234567890123.123'
30 31 32 33
select sec_to_time(-9001.1), sec_to_time(-9001.1) / 1,
sec_to_time(-9001.1) / 1e0, sec_to_time(-9001) div 1;
sec_to_time(-9001.1)	sec_to_time(-9001.1) / 1	sec_to_time(-9001.1) / 1e0	sec_to_time(-9001) div 1
-02:30:01.1	-23001.10000	-23001.1	-23001
34 35 36 37
select sec_to_time(90011e-1), sec_to_time(1234567890123e30);
sec_to_time(90011e-1)	sec_to_time(1234567890123e30)
02:30:01.100000	838:59:59.999999
Warnings:
Sergei Golubchik's avatar
Sergei Golubchik committed
38
Warning	1292	Truncated incorrect time value: '1.234567890123e42'
39 40 41 42 43 44
select sec_to_time(1234567890123), sec_to_time('99999999999999999999999999999');
sec_to_time(1234567890123)	sec_to_time('99999999999999999999999999999')
838:59:59	838:59:59.999999
Warnings:
Warning	1292	Truncated incorrect time value: '1234567890123'
Warning	1292	Truncated incorrect time value: '99999999999999999999999999999'
45
select now()-curdate()*1000000-curtime();
46
now()-curdate()*1000000-curtime()
47
0
48
select strcmp(current_timestamp(),concat(current_date()," ",current_time()));
49 50
strcmp(current_timestamp(),concat(current_date()," ",current_time()))
0
51 52 53 54 55 56
select strcmp(localtime(),concat(current_date()," ",current_time()));
strcmp(localtime(),concat(current_date()," ",current_time()))
0
select strcmp(localtimestamp(),concat(current_date()," ",current_time()));
strcmp(localtimestamp(),concat(current_date()," ",current_time()))
0
57
select date_format("1997-01-02 03:04:05", "%M %W %D %Y %y %m %d %h %i %s %w");
58 59
date_format("1997-01-02 03:04:05", "%M %W %D %Y %y %m %d %h %i %s %w")
January Thursday 2nd 1997 97 01 02 03 04 05 4
60
select date_format("1997-01-02", concat("%M %W %D ","%Y %y %m %d %h %i %s %w"));
61 62
date_format("1997-01-02", concat("%M %W %D ","%Y %y %m %d %h %i %s %w"))
January Thursday 2nd 1997 97 01 02 12 00 00 4
63
select dayofmonth("1997-01-02"),dayofmonth(19970323);
64 65
dayofmonth("1997-01-02")	dayofmonth(19970323)
2	23
66
select month("1997-01-02"),year("98-02-03"),dayofyear("1997-12-31");
67 68
month("1997-01-02")	year("98-02-03")	dayofyear("1997-12-31")
1	1998	365
69
select month("2001-02-00"),year("2001-00-00");
70 71
month("2001-02-00")	year("2001-00-00")
2	2001
72
select DAYOFYEAR("1997-03-03"), WEEK("1998-03-03"), QUARTER(980303);
73 74
DAYOFYEAR("1997-03-03")	WEEK("1998-03-03")	QUARTER(980303)
62	9	1
75
select HOUR("1997-03-03 23:03:22"), MINUTE("23:03:22"), SECOND(230322);
76 77
HOUR("1997-03-03 23:03:22")	MINUTE("23:03:22")	SECOND(230322)
23	3	22
78 79
select TIME(230322), TIME(230322.33), TIME("230322.33");
TIME(230322)	TIME(230322.33)	TIME("230322.33")
80
23:03:22	23:03:22.33	23:03:22.33
81
select week(19980101),week(19970101),week(19980101,1),week(19970101,1);
82
week(19980101)	week(19970101)	week(19980101,1)	week(19970101,1)
83 84
0	0	1	1
select week(19981231),week(19971231),week(19981231,1),week(19971231,1);
85
week(19981231)	week(19971231)	week(19981231,1)	week(19971231,1)
86 87
52	52	53	53
select week(19950101),week(19950101,1);
88 89
week(19950101)	week(19950101,1)
1	0
90
select yearweek('1981-12-31',1),yearweek('1982-01-01',1),yearweek('1982-12-31',1),yearweek('1983-01-01',1);
91 92
yearweek('1981-12-31',1)	yearweek('1982-01-01',1)	yearweek('1982-12-31',1)	yearweek('1983-01-01',1)
198153	198153	198252	198252
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119
select yearweek('1987-01-01',1),yearweek('1987-01-01');
yearweek('1987-01-01',1)	yearweek('1987-01-01')
198701	198652
select week("2000-01-01",0) as '2000', week("2001-01-01",0) as '2001', week("2002-01-01",0) as '2002',week("2003-01-01",0) as '2003', week("2004-01-01",0) as '2004', week("2005-01-01",0) as '2005', week("2006-01-01",0) as '2006';
2000	2001	2002	2003	2004	2005	2006
0	0	0	0	0	0	1
select week("2000-01-06",0) as '2000', week("2001-01-06",0) as '2001', week("2002-01-06",0) as '2002',week("2003-01-06",0) as '2003', week("2004-01-06",0) as '2004', week("2005-01-06",0) as '2005', week("2006-01-06",0) as '2006';
2000	2001	2002	2003	2004	2005	2006
1	0	1	1	1	1	1
select week("2000-01-01",1) as '2000', week("2001-01-01",1) as '2001', week("2002-01-01",1) as '2002',week("2003-01-01",1) as '2003', week("2004-01-01",1) as '2004', week("2005-01-01",1) as '2005', week("2006-01-01",1) as '2006';
2000	2001	2002	2003	2004	2005	2006
0	1	1	1	1	0	0
select week("2000-01-06",1) as '2000', week("2001-01-06",1) as '2001', week("2002-01-06",1) as '2002',week("2003-01-06",1) as '2003', week("2004-01-06",1) as '2004', week("2005-01-06",1) as '2005', week("2006-01-06",1) as '2006';
2000	2001	2002	2003	2004	2005	2006
1	1	1	2	2	1	1
select yearweek("2000-01-01",0) as '2000', yearweek("2001-01-01",0) as '2001', yearweek("2002-01-01",0) as '2002',yearweek("2003-01-01",0) as '2003', yearweek("2004-01-01",0) as '2004', yearweek("2005-01-01",0) as '2005', yearweek("2006-01-01",0) as '2006';
2000	2001	2002	2003	2004	2005	2006
199952	200053	200152	200252	200352	200452	200601
select yearweek("2000-01-06",0) as '2000', yearweek("2001-01-06",0) as '2001', yearweek("2002-01-06",0) as '2002',yearweek("2003-01-06",0) as '2003', yearweek("2004-01-06",0) as '2004', yearweek("2005-01-06",0) as '2005', yearweek("2006-01-06",0) as '2006';
2000	2001	2002	2003	2004	2005	2006
200001	200053	200201	200301	200401	200501	200601
select yearweek("2000-01-01",1) as '2000', yearweek("2001-01-01",1) as '2001', yearweek("2002-01-01",1) as '2002',yearweek("2003-01-01",1) as '2003', yearweek("2004-01-01",1) as '2004', yearweek("2005-01-01",1) as '2005', yearweek("2006-01-01",1) as '2006';
2000	2001	2002	2003	2004	2005	2006
199952	200101	200201	200301	200401	200453	200552
select yearweek("2000-01-06",1) as '2000', yearweek("2001-01-06",1) as '2001', yearweek("2002-01-06",1) as '2002',yearweek("2003-01-06",1) as '2003', yearweek("2004-01-06",1) as '2004', yearweek("2005-01-06",1) as '2005', yearweek("2006-01-06",1) as '2006';
2000	2001	2002	2003	2004	2005	2006
200001	200101	200201	200302	200402	200501	200601
120 121 122 123 124
select week(19981231,2), week(19981231,3), week(20000101,2), week(20000101,3);
week(19981231,2)	week(19981231,3)	week(20000101,2)	week(20000101,3)
52	53	52	52
select week(20001231,2),week(20001231,3);
week(20001231,2)	week(20001231,3)
125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148
53	52
select week(19981231,0) as '0', week(19981231,1) as '1', week(19981231,2) as '2', week(19981231,3) as '3', week(19981231,4) as '4', week(19981231,5) as '5', week(19981231,6) as '6', week(19981231,7) as '7';
0	1	2	3	4	5	6	7
52	53	52	53	52	52	52	52
select week(20000101,0) as '0', week(20000101,1) as '1', week(20000101,2) as '2', week(20000101,3) as '3', week(20000101,4) as '4', week(20000101,5) as '5', week(20000101,6) as '6', week(20000101,7) as '7';
0	1	2	3	4	5	6	7
0	0	52	52	0	0	52	52
select week(20000106,0) as '0', week(20000106,1) as '1', week(20000106,2) as '2', week(20000106,3) as '3', week(20000106,4) as '4', week(20000106,5) as '5', week(20000106,6) as '6', week(20000106,7) as '7';
0	1	2	3	4	5	6	7
1	1	1	1	1	1	1	1
select week(20001231,0) as '0', week(20001231,1) as '1', week(20001231,2) as '2', week(20001231,3) as '3', week(20001231,4) as '4', week(20001231,5) as '5', week(20001231,6) as '6', week(20001231,7) as '7';
0	1	2	3	4	5	6	7
53	52	53	52	53	52	1	52
select week(20010101,0) as '0', week(20010101,1) as '1', week(20010101,2) as '2', week(20010101,3) as '3', week(20010101,4) as '4', week(20010101,5) as '5', week(20010101,6) as '6', week(20010101,7) as '7';
0	1	2	3	4	5	6	7
0	1	53	1	1	1	1	1
select yearweek(20001231,0), yearweek(20001231,1), yearweek(20001231,2), yearweek(20001231,3), yearweek(20001231,4), yearweek(20001231,5), yearweek(20001231,6), yearweek(20001231,7);
yearweek(20001231,0)	yearweek(20001231,1)	yearweek(20001231,2)	yearweek(20001231,3)	yearweek(20001231,4)	yearweek(20001231,5)	yearweek(20001231,6)	yearweek(20001231,7)
200053	200052	200053	200052	200101	200052	200101	200052
set default_week_format = 6;
select week(20001231), week(20001231,6);
week(20001231)	week(20001231,6)
1	1
set default_week_format = 0;
149 150 151
set default_week_format = 2;
select week(20001231),week(20001231,2),week(20001231,0);
week(20001231)	week(20001231,2)	week(20001231,0)
152
53	53	53
153
set default_week_format = 0;
154
select date_format('1998-12-31','%x-%v'),date_format('1999-01-01','%x-%v');
155 156
date_format('1998-12-31','%x-%v')	date_format('1999-01-01','%x-%v')
1998-53	1998-53
157
select date_format('1999-12-31','%x-%v'),date_format('2000-01-01','%x-%v');
158 159
date_format('1999-12-31','%x-%v')	date_format('2000-01-01','%x-%v')
1999-52	1999-52
160
select dayname("1962-03-03"),dayname("1962-03-03")+0;
161 162
dayname("1962-03-03")	dayname("1962-03-03")+0
Saturday	5
163
select monthname("1972-03-04"),monthname("1972-03-04")+0;
164
monthname("1972-03-04")	monthname("1972-03-04")+0
165
March	0
166 167 168 169 170 171 172 173 174 175 176 177
select time_format(000000,'%H|%I|%k|%l|%i|%p|%r|%S|%T'),date_format(19980131000000,'%H|%I|%k|%l|%i|%p|%r|%S|%T');
time_format(000000,'%H|%I|%k|%l|%i|%p|%r|%S|%T')	date_format(19980131000000,'%H|%I|%k|%l|%i|%p|%r|%S|%T')
00|12|0|12|00|AM|12:00:00 AM|00|00:00:00	00|12|0|12|00|AM|12:00:00 AM|00|00:00:00
select time_format(010203,'%H|%I|%k|%l|%i|%p|%r|%S|%T'),date_format(19980131010203,'%H|%I|%k|%l|%i|%p|%r|%S|%T');
time_format(010203,'%H|%I|%k|%l|%i|%p|%r|%S|%T')	date_format(19980131010203,'%H|%I|%k|%l|%i|%p|%r|%S|%T')
01|01|1|1|02|AM|01:02:03 AM|03|01:02:03	01|01|1|1|02|AM|01:02:03 AM|03|01:02:03
select time_format(131415,'%H|%I|%k|%l|%i|%p|%r|%S|%T'),date_format(19980131131415,'%H|%I|%k|%l|%i|%p|%r|%S|%T');
time_format(131415,'%H|%I|%k|%l|%i|%p|%r|%S|%T')	date_format(19980131131415,'%H|%I|%k|%l|%i|%p|%r|%S|%T')
13|01|13|1|14|PM|01:14:15 PM|15|13:14:15	13|01|13|1|14|PM|01:14:15 PM|15|13:14:15
select time_format(010015,'%H|%I|%k|%l|%i|%p|%r|%S|%T'),date_format(19980131010015,'%H|%I|%k|%l|%i|%p|%r|%S|%T');
time_format(010015,'%H|%I|%k|%l|%i|%p|%r|%S|%T')	date_format(19980131010015,'%H|%I|%k|%l|%i|%p|%r|%S|%T')
01|01|1|1|00|AM|01:00:15 AM|15|01:00:15	01|01|1|1|00|AM|01:00:15 AM|15|01:00:15
178
select date_format(concat('19980131',131415),'%H|%I|%k|%l|%i|%p|%r|%S|%T| %M|%W|%D|%Y|%y|%a|%b|%j|%m|%d|%h|%s|%w');
179 180
date_format(concat('19980131',131415),'%H|%I|%k|%l|%i|%p|%r|%S|%T| %M|%W|%D|%Y|%y|%a|%b|%j|%m|%d|%h|%s|%w')
13|01|13|1|14|PM|01:14:15 PM|15|13:14:15| January|Saturday|31st|1998|98|Sat|Jan|031|01|31|01|15|6
181
select date_format(19980021000000,'%H|%I|%k|%l|%i|%p|%r|%S|%T| %M|%W|%D|%Y|%y|%a|%b|%j|%m|%d|%h|%s|%w');
182 183
date_format(19980021000000,'%H|%I|%k|%l|%i|%p|%r|%S|%T| %M|%W|%D|%Y|%y|%a|%b|%j|%m|%d|%h|%s|%w')
NULL
184
select date_add("1997-12-31 23:59:59",INTERVAL 1 SECOND);
185 186
date_add("1997-12-31 23:59:59",INTERVAL 1 SECOND)
1998-01-01 00:00:00
187
select date_add("1997-12-31 23:59:59",INTERVAL 1 MINUTE);
188 189
date_add("1997-12-31 23:59:59",INTERVAL 1 MINUTE)
1998-01-01 00:00:59
190
select date_add("1997-12-31 23:59:59",INTERVAL 1 HOUR);
191 192
date_add("1997-12-31 23:59:59",INTERVAL 1 HOUR)
1998-01-01 00:59:59
193
select date_add("1997-12-31 23:59:59",INTERVAL 1 DAY);
194 195
date_add("1997-12-31 23:59:59",INTERVAL 1 DAY)
1998-01-01 23:59:59
196
select date_add("1997-12-31 23:59:59",INTERVAL 1 MONTH);
197 198
date_add("1997-12-31 23:59:59",INTERVAL 1 MONTH)
1998-01-31 23:59:59
199
select date_add("1997-12-31 23:59:59",INTERVAL 1 YEAR);
200 201
date_add("1997-12-31 23:59:59",INTERVAL 1 YEAR)
1998-12-31 23:59:59
202
select date_add("1997-12-31 23:59:59",INTERVAL "1:1" MINUTE_SECOND);
203 204
date_add("1997-12-31 23:59:59",INTERVAL "1:1" MINUTE_SECOND)
1998-01-01 00:01:00
205
select date_add("1997-12-31 23:59:59",INTERVAL "1:1" HOUR_MINUTE);
206 207
date_add("1997-12-31 23:59:59",INTERVAL "1:1" HOUR_MINUTE)
1998-01-01 01:00:59
208
select date_add("1997-12-31 23:59:59",INTERVAL "1:1" DAY_HOUR);
209 210
date_add("1997-12-31 23:59:59",INTERVAL "1:1" DAY_HOUR)
1998-01-02 00:59:59
211
select date_add("1997-12-31 23:59:59",INTERVAL "1 1" YEAR_MONTH);
212 213
date_add("1997-12-31 23:59:59",INTERVAL "1 1" YEAR_MONTH)
1999-01-31 23:59:59
214
select date_add("1997-12-31 23:59:59",INTERVAL "1:1:1" HOUR_SECOND);
215 216
date_add("1997-12-31 23:59:59",INTERVAL "1:1:1" HOUR_SECOND)
1998-01-01 01:01:00
217
select date_add("1997-12-31 23:59:59",INTERVAL "1 1:1" DAY_MINUTE);
218 219
date_add("1997-12-31 23:59:59",INTERVAL "1 1:1" DAY_MINUTE)
1998-01-02 01:00:59
220
select date_add("1997-12-31 23:59:59",INTERVAL "1 1:1:1" DAY_SECOND);
221 222
date_add("1997-12-31 23:59:59",INTERVAL "1 1:1:1" DAY_SECOND)
1998-01-02 01:01:00
223
select date_sub("1998-01-01 00:00:00",INTERVAL 1 SECOND);
224 225
date_sub("1998-01-01 00:00:00",INTERVAL 1 SECOND)
1997-12-31 23:59:59
226
select date_sub("1998-01-01 00:00:00",INTERVAL 1 MINUTE);
227 228
date_sub("1998-01-01 00:00:00",INTERVAL 1 MINUTE)
1997-12-31 23:59:00
229
select date_sub("1998-01-01 00:00:00",INTERVAL 1 HOUR);
230 231
date_sub("1998-01-01 00:00:00",INTERVAL 1 HOUR)
1997-12-31 23:00:00
232
select date_sub("1998-01-01 00:00:00",INTERVAL 1 DAY);
233 234
date_sub("1998-01-01 00:00:00",INTERVAL 1 DAY)
1997-12-31 00:00:00
235
select date_sub("1998-01-01 00:00:00",INTERVAL 1 MONTH);
236 237
date_sub("1998-01-01 00:00:00",INTERVAL 1 MONTH)
1997-12-01 00:00:00
238
select date_sub("1998-01-01 00:00:00",INTERVAL 1 YEAR);
239 240
date_sub("1998-01-01 00:00:00",INTERVAL 1 YEAR)
1997-01-01 00:00:00
241
select date_sub("1998-01-01 00:00:00",INTERVAL "1:1" MINUTE_SECOND);
242 243
date_sub("1998-01-01 00:00:00",INTERVAL "1:1" MINUTE_SECOND)
1997-12-31 23:58:59
244
select date_sub("1998-01-01 00:00:00",INTERVAL "1:1" HOUR_MINUTE);
245 246
date_sub("1998-01-01 00:00:00",INTERVAL "1:1" HOUR_MINUTE)
1997-12-31 22:59:00
247
select date_sub("1998-01-01 00:00:00",INTERVAL "1:1" DAY_HOUR);
248 249
date_sub("1998-01-01 00:00:00",INTERVAL "1:1" DAY_HOUR)
1997-12-30 23:00:00
250
select date_sub("1998-01-01 00:00:00",INTERVAL "1 1" YEAR_MONTH);
251 252
date_sub("1998-01-01 00:00:00",INTERVAL "1 1" YEAR_MONTH)
1996-12-01 00:00:00
253
select date_sub("1998-01-01 00:00:00",INTERVAL "1:1:1" HOUR_SECOND);
254 255
date_sub("1998-01-01 00:00:00",INTERVAL "1:1:1" HOUR_SECOND)
1997-12-31 22:58:59
256
select date_sub("1998-01-01 00:00:00",INTERVAL "1 1:1" DAY_MINUTE);
257 258
date_sub("1998-01-01 00:00:00",INTERVAL "1 1:1" DAY_MINUTE)
1997-12-30 22:59:00
259
select date_sub("1998-01-01 00:00:00",INTERVAL "1 1:1:1" DAY_SECOND);
260 261
date_sub("1998-01-01 00:00:00",INTERVAL "1 1:1:1" DAY_SECOND)
1997-12-30 22:58:59
262
select date_add("1997-12-31 23:59:59",INTERVAL 100000 SECOND);
263 264
date_add("1997-12-31 23:59:59",INTERVAL 100000 SECOND)
1998-01-02 03:46:39
265
select date_add("1997-12-31 23:59:59",INTERVAL -100000 MINUTE);
266 267
date_add("1997-12-31 23:59:59",INTERVAL -100000 MINUTE)
1997-10-23 13:19:59
268
select date_add("1997-12-31 23:59:59",INTERVAL 100000 HOUR);
269 270
date_add("1997-12-31 23:59:59",INTERVAL 100000 HOUR)
2009-05-29 15:59:59
271
select date_add("1997-12-31 23:59:59",INTERVAL -100000 DAY);
272 273
date_add("1997-12-31 23:59:59",INTERVAL -100000 DAY)
1724-03-17 23:59:59
274
select date_add("1997-12-31 23:59:59",INTERVAL 100000 MONTH);
275 276
date_add("1997-12-31 23:59:59",INTERVAL 100000 MONTH)
NULL
unknown's avatar
unknown committed
277 278
Warnings:
Warning	1441	Datetime function: datetime field overflow
279
select date_add("1997-12-31 23:59:59",INTERVAL -100000 YEAR);
280 281
date_add("1997-12-31 23:59:59",INTERVAL -100000 YEAR)
NULL
unknown's avatar
unknown committed
282 283
Warnings:
Warning	1441	Datetime function: datetime field overflow
284
select date_add("1997-12-31 23:59:59",INTERVAL "10000:1" MINUTE_SECOND);
285 286
date_add("1997-12-31 23:59:59",INTERVAL "10000:1" MINUTE_SECOND)
1998-01-07 22:40:00
287
select date_add("1997-12-31 23:59:59",INTERVAL "-10000:1" HOUR_MINUTE);
288 289
date_add("1997-12-31 23:59:59",INTERVAL "-10000:1" HOUR_MINUTE)
1996-11-10 07:58:59
290
select date_add("1997-12-31 23:59:59",INTERVAL "10000:1" DAY_HOUR);
291 292
date_add("1997-12-31 23:59:59",INTERVAL "10000:1" DAY_HOUR)
2025-05-19 00:59:59
293
select date_add("1997-12-31 23:59:59",INTERVAL "-100 1" YEAR_MONTH);
294 295
date_add("1997-12-31 23:59:59",INTERVAL "-100 1" YEAR_MONTH)
1897-11-30 23:59:59
296
select date_add("1997-12-31 23:59:59",INTERVAL "10000:99:99" HOUR_SECOND);
297 298
date_add("1997-12-31 23:59:59",INTERVAL "10000:99:99" HOUR_SECOND)
1999-02-21 17:40:38
299
select date_add("1997-12-31 23:59:59",INTERVAL " -10000 99:99" DAY_MINUTE);
300 301
date_add("1997-12-31 23:59:59",INTERVAL " -10000 99:99" DAY_MINUTE)
1970-08-11 19:20:59
302
select date_add("1997-12-31 23:59:59",INTERVAL "10000 99:99:99" DAY_SECOND);
303 304
date_add("1997-12-31 23:59:59",INTERVAL "10000 99:99:99" DAY_SECOND)
2025-05-23 04:40:38
305
select "1997-12-31 23:59:59" + INTERVAL 1 SECOND;
306 307
"1997-12-31 23:59:59" + INTERVAL 1 SECOND
1998-01-01 00:00:00
308
select INTERVAL 1 DAY + "1997-12-31";
309 310
INTERVAL 1 DAY + "1997-12-31"
1998-01-01
311
select "1998-01-01 00:00:00" - INTERVAL 1 SECOND;
312 313
"1998-01-01 00:00:00" - INTERVAL 1 SECOND
1997-12-31 23:59:59
314
select date_sub("1998-01-02",INTERVAL 31 DAY);
315 316
date_sub("1998-01-02",INTERVAL 31 DAY)
1997-12-02
317
select date_add("1997-12-31",INTERVAL 1 SECOND);
318 319
date_add("1997-12-31",INTERVAL 1 SECOND)
1997-12-31 00:00:01
320
select date_add("1997-12-31",INTERVAL 1 DAY);
321 322
date_add("1997-12-31",INTERVAL 1 DAY)
1998-01-01
323
select date_add(NULL,INTERVAL 100000 SECOND);
324 325
date_add(NULL,INTERVAL 100000 SECOND)
NULL
326
select date_add("1997-12-31 23:59:59",INTERVAL NULL SECOND);
327 328
date_add("1997-12-31 23:59:59",INTERVAL NULL SECOND)
NULL
329
select date_add("1997-12-31 23:59:59",INTERVAL NULL MINUTE_SECOND);
330 331
date_add("1997-12-31 23:59:59",INTERVAL NULL MINUTE_SECOND)
NULL
332
select date_add("9999-12-31 23:59:59",INTERVAL 1 SECOND);
333 334
date_add("9999-12-31 23:59:59",INTERVAL 1 SECOND)
NULL
unknown's avatar
unknown committed
335 336
Warnings:
Warning	1441	Datetime function: datetime field overflow
337
select date_sub("0000-00-00 00:00:00",INTERVAL 1 SECOND);
338 339
date_sub("0000-00-00 00:00:00",INTERVAL 1 SECOND)
NULL
340
Warnings:
341
Warning	1292	Incorrect datetime value: '0000-00-00 00:00:00'
342
select date_add('1998-01-30',Interval 1 month);
343 344
date_add('1998-01-30',Interval 1 month)
1998-02-28
345
select date_add('1998-01-30',Interval '2:1' year_month);
346 347
date_add('1998-01-30',Interval '2:1' year_month)
2000-02-29
348
select date_add('1996-02-29',Interval '1' year);
349 350
date_add('1996-02-29',Interval '1' year)
1997-02-28
351
select extract(YEAR FROM "1999-01-02 10:11:12");
352 353
extract(YEAR FROM "1999-01-02 10:11:12")
1999
354
select extract(YEAR_MONTH FROM "1999-01-02");
355 356
extract(YEAR_MONTH FROM "1999-01-02")
199901
357
select extract(DAY FROM "1999-01-02");
358 359
extract(DAY FROM "1999-01-02")
2
360
select extract(DAY_HOUR FROM "1999-01-02 10:11:12");
361 362
extract(DAY_HOUR FROM "1999-01-02 10:11:12")
210
363
select extract(DAY_MINUTE FROM "02 10:11:12");
364 365
extract(DAY_MINUTE FROM "02 10:11:12")
21011
366
select extract(DAY_SECOND FROM "225 10:11:12");
367
extract(DAY_SECOND FROM "225 10:11:12")
368
34225959
369 370
Warnings:
Warning	1292	Truncated incorrect time value: '225 10:11:12'
371
select extract(HOUR FROM "1999-01-02 10:11:12");
372 373
extract(HOUR FROM "1999-01-02 10:11:12")
10
374
select extract(HOUR_MINUTE FROM "10:11:12");
375 376
extract(HOUR_MINUTE FROM "10:11:12")
1011
377
select extract(HOUR_SECOND FROM "10:11:12");
378 379
extract(HOUR_SECOND FROM "10:11:12")
101112
380
select extract(MINUTE FROM "10:11:12");
381 382
extract(MINUTE FROM "10:11:12")
11
383
select extract(MINUTE_SECOND FROM "10:11:12");
384 385
extract(MINUTE_SECOND FROM "10:11:12")
1112
386
select extract(SECOND FROM "1999-01-02 10:11:12");
387 388
extract(SECOND FROM "1999-01-02 10:11:12")
12
389
select extract(MONTH FROM "2001-02-00");
390 391
extract(MONTH FROM "2001-02-00")
2
392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427
SELECT EXTRACT(QUARTER FROM '2004-01-15') AS quarter;
quarter
1
SELECT EXTRACT(QUARTER FROM '2004-02-15') AS quarter;
quarter
1
SELECT EXTRACT(QUARTER FROM '2004-03-15') AS quarter;
quarter
1
SELECT EXTRACT(QUARTER FROM '2004-04-15') AS quarter;
quarter
2
SELECT EXTRACT(QUARTER FROM '2004-05-15') AS quarter;
quarter
2
SELECT EXTRACT(QUARTER FROM '2004-06-15') AS quarter;
quarter
2
SELECT EXTRACT(QUARTER FROM '2004-07-15') AS quarter;
quarter
3
SELECT EXTRACT(QUARTER FROM '2004-08-15') AS quarter;
quarter
3
SELECT EXTRACT(QUARTER FROM '2004-09-15') AS quarter;
quarter
3
SELECT EXTRACT(QUARTER FROM '2004-10-15') AS quarter;
quarter
4
SELECT EXTRACT(QUARTER FROM '2004-11-15') AS quarter;
quarter
4
SELECT EXTRACT(QUARTER FROM '2004-12-15') AS quarter;
quarter
4
428 429 430 431 432 433
SELECT DATE_SUB(str_to_date('9999-12-31 00:01:00','%Y-%m-%d %H:%i:%s'), INTERVAL 1 MINUTE);
DATE_SUB(str_to_date('9999-12-31 00:01:00','%Y-%m-%d %H:%i:%s'), INTERVAL 1 MINUTE)
9999-12-31 00:00:00
SELECT DATE_ADD(str_to_date('9999-12-30 23:59:00','%Y-%m-%d %H:%i:%s'), INTERVAL 1 MINUTE);
DATE_ADD(str_to_date('9999-12-30 23:59:00','%Y-%m-%d %H:%i:%s'), INTERVAL 1 MINUTE)
9999-12-31 00:00:00
434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454
SELECT "1900-01-01 00:00:00" + INTERVAL 2147483648 SECOND;
"1900-01-01 00:00:00" + INTERVAL 2147483648 SECOND
1968-01-20 03:14:08
SELECT "1900-01-01 00:00:00" + INTERVAL "1:2147483647" MINUTE_SECOND;
"1900-01-01 00:00:00" + INTERVAL "1:2147483647" MINUTE_SECOND
1968-01-20 03:15:07
SELECT "1900-01-01 00:00:00" + INTERVAL "100000000:214748364700" MINUTE_SECOND;
"1900-01-01 00:00:00" + INTERVAL "100000000:214748364700" MINUTE_SECOND
8895-03-27 22:11:40
SELECT "1900-01-01 00:00:00" + INTERVAL 1<<37 SECOND;
"1900-01-01 00:00:00" + INTERVAL 1<<37 SECOND
6255-04-08 15:04:32
SELECT "1900-01-01 00:00:00" + INTERVAL 1<<31 MINUTE;
"1900-01-01 00:00:00" + INTERVAL 1<<31 MINUTE
5983-01-24 02:08:00
SELECT "1900-01-01 00:00:00" + INTERVAL 1<<20 HOUR;
"1900-01-01 00:00:00" + INTERVAL 1<<20 HOUR
2019-08-15 16:00:00
SELECT "1900-01-01 00:00:00" + INTERVAL 1<<38 SECOND;
"1900-01-01 00:00:00" + INTERVAL 1<<38 SECOND
NULL
unknown's avatar
unknown committed
455 456
Warnings:
Warning	1441	Datetime function: datetime field overflow
457 458 459
SELECT "1900-01-01 00:00:00" + INTERVAL 1<<33 MINUTE;
"1900-01-01 00:00:00" + INTERVAL 1<<33 MINUTE
NULL
unknown's avatar
unknown committed
460 461
Warnings:
Warning	1441	Datetime function: datetime field overflow
462 463 464
SELECT "1900-01-01 00:00:00" + INTERVAL 1<<30 HOUR;
"1900-01-01 00:00:00" + INTERVAL 1<<30 HOUR
NULL
unknown's avatar
unknown committed
465 466
Warnings:
Warning	1441	Datetime function: datetime field overflow
467 468 469
SELECT "1900-01-01 00:00:00" + INTERVAL "1000000000:214748364700" MINUTE_SECOND;
"1900-01-01 00:00:00" + INTERVAL "1000000000:214748364700" MINUTE_SECOND
NULL
unknown's avatar
unknown committed
470 471
Warnings:
Warning	1441	Datetime function: datetime field overflow
472 473 474
create table t1 (ctime varchar(20));
insert into t1 values ('2001-01-12 12:23:40');
select ctime, hour(ctime) from t1;
unknown's avatar
unknown committed
475 476
ctime	hour(ctime)
2001-01-12 12:23:40	12
unknown's avatar
unknown committed
477 478 479
select ctime from t1 where extract(MONTH FROM ctime) = 1 AND extract(YEAR FROM ctime) = 2001;
ctime
2001-01-12 12:23:40
480 481 482 483 484 485 486 487
drop table t1;
create table t1 (id int);
create table t2 (id int, date date);
insert into t1 values (1);
insert into t2 values (1, "0000-00-00");
insert into t1 values (2);
insert into t2 values (2, "2000-01-01");
select monthname(date) from t1 inner join t2 on t1.id = t2.id;
488 489 490
monthname(date)
NULL
January
491
select monthname(date) from t1 inner join t2 on t1.id = t2.id order by t1.id;
492 493 494
monthname(date)
NULL
January
495
drop table t1,t2;
unknown's avatar
unknown committed
496
CREATE TABLE t1 (updated text) ENGINE=MyISAM;
497 498
INSERT INTO t1 VALUES ('');
SELECT month(updated) from t1;
unknown's avatar
unknown committed
499 500
month(updated)
NULL
501
Warnings:
502
Warning	1292	Incorrect datetime value: ''
503
SELECT year(updated) from t1;
unknown's avatar
unknown committed
504 505
year(updated)
NULL
506
Warnings:
507
Warning	1292	Incorrect datetime value: ''
508
drop table t1;
509 510 511 512 513
create table t1 (d date, dt datetime, t timestamp, c char(10));
insert into t1 values ("0000-00-00", "0000-00-00", "0000-00-00", "0000-00-00");
select dayofyear("0000-00-00"),dayofyear(d),dayofyear(dt),dayofyear(t),dayofyear(c) from t1;
dayofyear("0000-00-00")	dayofyear(d)	dayofyear(dt)	dayofyear(t)	dayofyear(c)
NULL	NULL	NULL	NULL	NULL
514
Warnings:
515 516
Warning	1292	Incorrect datetime value: '0000-00-00'
Warning	1292	Incorrect datetime value: '0000-00-00'
517 518 519 520 521 522 523 524 525 526 527 528
select dayofmonth("0000-00-00"),dayofmonth(d),dayofmonth(dt),dayofmonth(t),dayofmonth(c) from t1;
dayofmonth("0000-00-00")	dayofmonth(d)	dayofmonth(dt)	dayofmonth(t)	dayofmonth(c)
0	0	0	0	0
select month("0000-00-00"),month(d),month(dt),month(t),month(c) from t1;
month("0000-00-00")	month(d)	month(dt)	month(t)	month(c)
0	0	0	0	0
select quarter("0000-00-00"),quarter(d),quarter(dt),quarter(t),quarter(c) from t1;
quarter("0000-00-00")	quarter(d)	quarter(dt)	quarter(t)	quarter(c)
0	0	0	0	0
select week("0000-00-00"),week(d),week(dt),week(t),week(c) from t1;
week("0000-00-00")	week(d)	week(dt)	week(t)	week(c)
NULL	NULL	NULL	NULL	NULL
529
Warnings:
530 531
Warning	1292	Incorrect datetime value: '0000-00-00'
Warning	1292	Incorrect datetime value: '0000-00-00'
532 533 534 535 536 537
select year("0000-00-00"),year(d),year(dt),year(t),year(c) from t1;
year("0000-00-00")	year(d)	year(dt)	year(t)	year(c)
0	0	0	0	0
select yearweek("0000-00-00"),yearweek(d),yearweek(dt),yearweek(t),yearweek(c) from t1;
yearweek("0000-00-00")	yearweek(d)	yearweek(dt)	yearweek(t)	yearweek(c)
NULL	NULL	NULL	NULL	NULL
538
Warnings:
539 540
Warning	1292	Incorrect datetime value: '0000-00-00'
Warning	1292	Incorrect datetime value: '0000-00-00'
541 542 543
select to_days("0000-00-00"),to_days(d),to_days(dt),to_days(t),to_days(c) from t1;
to_days("0000-00-00")	to_days(d)	to_days(dt)	to_days(t)	to_days(c)
NULL	NULL	NULL	NULL	NULL
544
Warnings:
545 546
Warning	1292	Incorrect datetime value: '0000-00-00'
Warning	1292	Incorrect datetime value: '0000-00-00'
547 548 549 550
select extract(MONTH FROM "0000-00-00"),extract(MONTH FROM d),extract(MONTH FROM dt),extract(MONTH FROM t),extract(MONTH FROM c) from t1;
extract(MONTH FROM "0000-00-00")	extract(MONTH FROM d)	extract(MONTH FROM dt)	extract(MONTH FROM t)	extract(MONTH FROM c)
0	0	0	0	0
drop table t1;
551 552
CREATE TABLE t1 ( start datetime default NULL);
INSERT INTO t1 VALUES ('2002-10-21 00:00:00'),('2002-10-28 00:00:00'),('2002-11-04 00:00:00');
553
CREATE TABLE t2 ( ctime1 timestamp NOT NULL, ctime2 timestamp NOT NULL);
554 555 556 557 558
INSERT INTO t2 VALUES (20021029165106,20021105164731);
CREATE TABLE t3 (ctime1 char(19) NOT NULL, ctime2 char(19) NOT NULL);
INSERT INTO t3 VALUES ("2002-10-29 16:51:06","2002-11-05 16:47:31");
select * from t1, t2 where t1.start between t2.ctime1 and t2.ctime2;
start	ctime1	ctime2
559
2002-11-04 00:00:00	2002-10-29 16:51:06	2002-11-05 16:47:31
560 561
select * from t1, t2 where t1.start >= t2.ctime1 and t1.start <= t2.ctime2;
start	ctime1	ctime2
562
2002-11-04 00:00:00	2002-10-29 16:51:06	2002-11-05 16:47:31
563 564 565 566
select * from t1, t3 where t1.start between t3.ctime1 and t3.ctime2;
start	ctime1	ctime2
2002-11-04 00:00:00	2002-10-29 16:51:06	2002-11-05 16:47:31
drop table t1,t2,t3;
unknown's avatar
unknown committed
567 568 569 570 571
select @a:=FROM_UNIXTIME(1);
@a:=FROM_UNIXTIME(1)
1970-01-01 03:00:01
select unix_timestamp(@a);
unix_timestamp(@a)
572
1
unknown's avatar
unknown committed
573 574
select unix_timestamp('1969-12-01 19:00:01');
unix_timestamp('1969-12-01 19:00:01')
575
NULL
576 577
select from_unixtime(-1);
from_unixtime(-1)
578
NULL
579 580 581 582 583
select from_unixtime(2147483647);
from_unixtime(2147483647)
2038-01-19 06:14:07
select from_unixtime(2147483648);
from_unixtime(2147483648)
584
NULL
585 586 587
select from_unixtime(0);
from_unixtime(0)
1970-01-01 03:00:00
588 589 590 591 592 593 594 595
select unix_timestamp(from_unixtime(2147483647));
unix_timestamp(from_unixtime(2147483647))
2147483647
select unix_timestamp(from_unixtime(2147483648));
unix_timestamp(from_unixtime(2147483648))
NULL
select unix_timestamp('2039-01-20 01:00:00');
unix_timestamp('2039-01-20 01:00:00')
596
NULL
597 598
select unix_timestamp('1968-01-20 01:00:00');
unix_timestamp('1968-01-20 01:00:00')
599
NULL
600 601
select unix_timestamp('2038-02-10 01:00:00');
unix_timestamp('2038-02-10 01:00:00')
602
NULL
603 604
select unix_timestamp('1969-11-20 01:00:00');
unix_timestamp('1969-11-20 01:00:00')
605
NULL
606 607
select unix_timestamp('2038-01-20 01:00:00');
unix_timestamp('2038-01-20 01:00:00')
608
NULL
609 610
select unix_timestamp('1969-12-30 01:00:00');
unix_timestamp('1969-12-30 01:00:00')
611
NULL
612 613
select unix_timestamp('2038-01-17 12:00:00');
unix_timestamp('2038-01-17 12:00:00')
614
2147331600
615 616
select unix_timestamp('1970-01-01 03:00:01');
unix_timestamp('1970-01-01 03:00:01')
617
1
618 619
select unix_timestamp('2038-01-19 07:14:07');
unix_timestamp('2038-01-19 07:14:07')
620
NULL
621 622 623 624 625 626 627 628 629 630 631 632 633 634 635
SELECT CHARSET(DAYNAME(19700101));
CHARSET(DAYNAME(19700101))
latin1
SELECT CHARSET(MONTHNAME(19700101));
CHARSET(MONTHNAME(19700101))
latin1
SELECT LOWER(DAYNAME(19700101));
LOWER(DAYNAME(19700101))
thursday
SELECT LOWER(MONTHNAME(19700101));
LOWER(MONTHNAME(19700101))
january
SELECT COERCIBILITY(MONTHNAME('1970-01-01')),COERCIBILITY(DAYNAME('1970-01-01'));
COERCIBILITY(MONTHNAME('1970-01-01'))	COERCIBILITY(DAYNAME('1970-01-01'))
4	4
unknown's avatar
unknown committed
636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691
CREATE TABLE t1 (datetime datetime, timestamp timestamp, date date, time time);
INSERT INTO t1 values ("2001-01-02 03:04:05", "2002-01-02 03:04:05", "2003-01-02", "06:07:08");
SELECT * from t1;
datetime	timestamp	date	time
2001-01-02 03:04:05	2002-01-02 03:04:05	2003-01-02	06:07:08
select date_add("1997-12-31",INTERVAL 1 SECOND);
date_add("1997-12-31",INTERVAL 1 SECOND)
1997-12-31 00:00:01
select date_add("1997-12-31",INTERVAL "1 1" YEAR_MONTH);
date_add("1997-12-31",INTERVAL "1 1" YEAR_MONTH)
1999-01-31
select date_add(datetime, INTERVAL 1 SECOND) from t1;
date_add(datetime, INTERVAL 1 SECOND)
2001-01-02 03:04:06
select date_add(datetime, INTERVAL 1 YEAR) from t1;
date_add(datetime, INTERVAL 1 YEAR)
2002-01-02 03:04:05
select date_add(date,INTERVAL 1 SECOND) from t1;
date_add(date,INTERVAL 1 SECOND)
2003-01-02 00:00:01
select date_add(date,INTERVAL 1 MINUTE) from t1;
date_add(date,INTERVAL 1 MINUTE)
2003-01-02 00:01:00
select date_add(date,INTERVAL 1 HOUR) from t1;
date_add(date,INTERVAL 1 HOUR)
2003-01-02 01:00:00
select date_add(date,INTERVAL 1 DAY) from t1;
date_add(date,INTERVAL 1 DAY)
2003-01-03
select date_add(date,INTERVAL 1 MONTH) from t1;
date_add(date,INTERVAL 1 MONTH)
2003-02-02
select date_add(date,INTERVAL 1 YEAR) from t1;
date_add(date,INTERVAL 1 YEAR)
2004-01-02
select date_add(date,INTERVAL "1:1" MINUTE_SECOND) from t1;
date_add(date,INTERVAL "1:1" MINUTE_SECOND)
2003-01-02 00:01:01
select date_add(date,INTERVAL "1:1" HOUR_MINUTE) from t1;
date_add(date,INTERVAL "1:1" HOUR_MINUTE)
2003-01-02 01:01:00
select date_add(date,INTERVAL "1:1" DAY_HOUR) from t1;
date_add(date,INTERVAL "1:1" DAY_HOUR)
2003-01-03 01:00:00
select date_add(date,INTERVAL "1 1" YEAR_MONTH) from t1;
date_add(date,INTERVAL "1 1" YEAR_MONTH)
2004-02-02
select date_add(date,INTERVAL "1:1:1" HOUR_SECOND) from t1;
date_add(date,INTERVAL "1:1:1" HOUR_SECOND)
2003-01-02 01:01:01
select date_add(date,INTERVAL "1 1:1" DAY_MINUTE) from t1;
date_add(date,INTERVAL "1 1:1" DAY_MINUTE)
2003-01-03 01:01:00
select date_add(date,INTERVAL "1 1:1:1" DAY_SECOND) from t1;
date_add(date,INTERVAL "1 1:1:1" DAY_SECOND)
2003-01-03 01:01:01
unknown's avatar
unknown committed
692 693
select date_add(date,INTERVAL "1" WEEK) from t1;
date_add(date,INTERVAL "1" WEEK)
694
2003-01-09
unknown's avatar
unknown committed
695 696 697 698 699 700 701 702
select date_add(date,INTERVAL "1" QUARTER) from t1;
date_add(date,INTERVAL "1" QUARTER)
2003-04-02
select timestampadd(MINUTE, 1, date) from t1;
timestampadd(MINUTE, 1, date)
2003-01-02 00:01:00
select timestampadd(WEEK, 1, date) from t1;
timestampadd(WEEK, 1, date)
703
2003-01-09
unknown's avatar
unknown committed
704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742
select timestampadd(SQL_TSI_SECOND, 1, date) from t1;
timestampadd(SQL_TSI_SECOND, 1, date)
2003-01-02 00:00:01
select timestampdiff(MONTH, '2001-02-01', '2001-05-01') as a;
a
3
select timestampdiff(YEAR, '2002-05-01', '2001-01-01') as a;
a
-1
select timestampdiff(QUARTER, '2002-05-01', '2001-01-01') as a;
a
-5
select timestampdiff(MONTH, '2000-03-28', '2000-02-29') as a;
a
0
select timestampdiff(MONTH, '1991-03-28', '2000-02-29') as a;
a
107
select timestampdiff(SQL_TSI_WEEK, '2001-02-01', '2001-05-01') as a;
a
12
select timestampdiff(SQL_TSI_HOUR, '2001-02-01', '2001-05-01') as a;
a
2136
select timestampdiff(SQL_TSI_DAY, '2001-02-01', '2001-05-01') as a;
a
89
select timestampdiff(SQL_TSI_MINUTE, '2001-02-01 12:59:59', '2001-05-01 12:58:59') as a;
a
128159
select timestampdiff(SQL_TSI_SECOND, '2001-02-01 12:59:59', '2001-05-01 12:58:58') as a;
a
7689539
select timestampdiff(SQL_TSI_DAY, '1986-02-01', '1986-03-01') as a1,
timestampdiff(SQL_TSI_DAY, '1900-02-01', '1900-03-01') as a2,
timestampdiff(SQL_TSI_DAY, '1996-02-01', '1996-03-01') as a3,
timestampdiff(SQL_TSI_DAY, '2000-02-01', '2000-03-01') as a4;
a1	a2	a3	a4
28	28	29	29
743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814
SELECT TIMESTAMPDIFF(day,'2006-01-10 14:30:28','2006-01-11 14:30:27');
TIMESTAMPDIFF(day,'2006-01-10 14:30:28','2006-01-11 14:30:27')
0
SELECT TIMESTAMPDIFF(day,'2006-01-10 14:30:28','2006-01-11 14:30:28');
TIMESTAMPDIFF(day,'2006-01-10 14:30:28','2006-01-11 14:30:28')
1
SELECT TIMESTAMPDIFF(day,'2006-01-10 14:30:28','2006-01-11 14:30:29');
TIMESTAMPDIFF(day,'2006-01-10 14:30:28','2006-01-11 14:30:29')
1
SELECT TIMESTAMPDIFF(day,'2006-01-10 14:30:28','2006-01-12 14:30:27');
TIMESTAMPDIFF(day,'2006-01-10 14:30:28','2006-01-12 14:30:27')
1
SELECT TIMESTAMPDIFF(day,'2006-01-10 14:30:28','2006-01-12 14:30:28');
TIMESTAMPDIFF(day,'2006-01-10 14:30:28','2006-01-12 14:30:28')
2
SELECT TIMESTAMPDIFF(day,'2006-01-10 14:30:28','2006-01-12 14:30:29');
TIMESTAMPDIFF(day,'2006-01-10 14:30:28','2006-01-12 14:30:29')
2
SELECT TIMESTAMPDIFF(week,'2006-01-10 14:30:28','2006-01-17 14:30:27');
TIMESTAMPDIFF(week,'2006-01-10 14:30:28','2006-01-17 14:30:27')
0
SELECT TIMESTAMPDIFF(week,'2006-01-10 14:30:28','2006-01-17 14:30:28');
TIMESTAMPDIFF(week,'2006-01-10 14:30:28','2006-01-17 14:30:28')
1
SELECT TIMESTAMPDIFF(week,'2006-01-10 14:30:28','2006-01-17 14:30:29');
TIMESTAMPDIFF(week,'2006-01-10 14:30:28','2006-01-17 14:30:29')
1
SELECT TIMESTAMPDIFF(week,'2006-01-10 14:30:28','2006-01-24 14:30:27');
TIMESTAMPDIFF(week,'2006-01-10 14:30:28','2006-01-24 14:30:27')
1
SELECT TIMESTAMPDIFF(week,'2006-01-10 14:30:28','2006-01-24 14:30:28');
TIMESTAMPDIFF(week,'2006-01-10 14:30:28','2006-01-24 14:30:28')
2
SELECT TIMESTAMPDIFF(week,'2006-01-10 14:30:28','2006-01-24 14:30:29');
TIMESTAMPDIFF(week,'2006-01-10 14:30:28','2006-01-24 14:30:29')
2
SELECT TIMESTAMPDIFF(month,'2006-01-10 14:30:28','2006-02-10 14:30:27');
TIMESTAMPDIFF(month,'2006-01-10 14:30:28','2006-02-10 14:30:27')
0
SELECT TIMESTAMPDIFF(month,'2006-01-10 14:30:28','2006-02-10 14:30:28');
TIMESTAMPDIFF(month,'2006-01-10 14:30:28','2006-02-10 14:30:28')
1
SELECT TIMESTAMPDIFF(month,'2006-01-10 14:30:28','2006-02-10 14:30:29');
TIMESTAMPDIFF(month,'2006-01-10 14:30:28','2006-02-10 14:30:29')
1
SELECT TIMESTAMPDIFF(month,'2006-01-10 14:30:28','2006-03-10 14:30:27');
TIMESTAMPDIFF(month,'2006-01-10 14:30:28','2006-03-10 14:30:27')
1
SELECT TIMESTAMPDIFF(month,'2006-01-10 14:30:28','2006-03-10 14:30:28');
TIMESTAMPDIFF(month,'2006-01-10 14:30:28','2006-03-10 14:30:28')
2
SELECT TIMESTAMPDIFF(month,'2006-01-10 14:30:28','2006-03-10 14:30:29');
TIMESTAMPDIFF(month,'2006-01-10 14:30:28','2006-03-10 14:30:29')
2
SELECT TIMESTAMPDIFF(year,'2006-01-10 14:30:28','2007-01-10 14:30:27');
TIMESTAMPDIFF(year,'2006-01-10 14:30:28','2007-01-10 14:30:27')
0
SELECT TIMESTAMPDIFF(year,'2006-01-10 14:30:28','2007-01-10 14:30:28');
TIMESTAMPDIFF(year,'2006-01-10 14:30:28','2007-01-10 14:30:28')
1
SELECT TIMESTAMPDIFF(year,'2006-01-10 14:30:28','2007-01-10 14:30:29');
TIMESTAMPDIFF(year,'2006-01-10 14:30:28','2007-01-10 14:30:29')
1
SELECT TIMESTAMPDIFF(year,'2006-01-10 14:30:28','2008-01-10 14:30:27');
TIMESTAMPDIFF(year,'2006-01-10 14:30:28','2008-01-10 14:30:27')
1
SELECT TIMESTAMPDIFF(year,'2006-01-10 14:30:28','2008-01-10 14:30:28');
TIMESTAMPDIFF(year,'2006-01-10 14:30:28','2008-01-10 14:30:28')
2
SELECT TIMESTAMPDIFF(year,'2006-01-10 14:30:28','2008-01-10 14:30:29');
TIMESTAMPDIFF(year,'2006-01-10 14:30:28','2008-01-10 14:30:29')
2
815 816
select date_add(time,INTERVAL 1 SECOND) from t1;
date_add(time,INTERVAL 1 SECOND)
817
06:07:09
818
drop table t1;
unknown's avatar
unknown committed
819 820 821 822 823 824
select last_day('2000-02-05') as f1, last_day('2002-12-31') as f2,
last_day('2003-03-32') as f3, last_day('2003-04-01') as f4,
last_day('2001-01-01 01:01:01') as f5, last_day(NULL),
last_day('2001-02-12');
f1	f2	f3	f4	f5	last_day(NULL)	last_day('2001-02-12')
2000-02-29	2002-12-31	NULL	2003-04-30	2001-01-31	NULL	2001-02-28
825
Warnings:
826
Warning	1292	Incorrect datetime value: '2003-03-32'
827 828
create table t1 select last_day('2000-02-05') as a,
from_days(to_days("960101")) as b;
unknown's avatar
unknown committed
829 830
describe t1;
Field	Type	Null	Key	Default	Extra
831
a	date	YES		NULL	
832
b	date	YES		NULL	
unknown's avatar
unknown committed
833
select * from t1;
834 835
a	b
2000-02-29	1996-01-01
unknown's avatar
unknown committed
836
drop table t1;
837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852
select last_day('2000-02-05') as a,
from_days(to_days("960101")) as b;
a	b
2000-02-29	1996-01-01
select date_add(last_day("1997-12-1"), INTERVAL 1 DAY);
date_add(last_day("1997-12-1"), INTERVAL 1 DAY)
1998-01-01
select length(last_day("1997-12-1"));
length(last_day("1997-12-1"))
10
select last_day("1997-12-1")+0;
last_day("1997-12-1")+0
19971231
select last_day("1997-12-1")+0.0;
last_day("1997-12-1")+0.0
19971231.0
853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870
select strcmp(date_sub(localtimestamp(), interval 3 hour), utc_timestamp())=0;
strcmp(date_sub(localtimestamp(), interval 3 hour), utc_timestamp())=0
1
select strcmp(date_format(date_sub(localtimestamp(), interval 3 hour),"%T"), utc_time())=0;
strcmp(date_format(date_sub(localtimestamp(), interval 3 hour),"%T"), utc_time())=0
1
select strcmp(date_format(date_sub(localtimestamp(), interval 3 hour),"%Y-%m-%d"), utc_date())=0;
strcmp(date_format(date_sub(localtimestamp(), interval 3 hour),"%Y-%m-%d"), utc_date())=0
1
select strcmp(date_format(utc_timestamp(),"%T"), utc_time())=0;
strcmp(date_format(utc_timestamp(),"%T"), utc_time())=0
1
select strcmp(date_format(utc_timestamp(),"%Y-%m-%d"), utc_date())=0;
strcmp(date_format(utc_timestamp(),"%Y-%m-%d"), utc_date())=0
1
select strcmp(concat(utc_date(),' ',utc_time()),utc_timestamp())=0;
strcmp(concat(utc_date(),' ',utc_time()),utc_timestamp())=0
1
871
explain extended select period_add("9602",-12),period_diff(199505,"9404"),from_days(to_days("960101")),dayofmonth("1997-01-02"), month("1997-01-02"), monthname("1972-03-04"),dayofyear("0000-00-00"),HOUR("1997-03-03 23:03:22"),MINUTE("23:03:22"),SECOND(230322),QUARTER(980303),WEEK("1998-03-03"),yearweek("2000-01-01",1),week(19950101,1),year("98-02-03"),weekday(curdate())-weekday(now()),dayname("1962-03-03"),unix_timestamp(),sec_to_time(time_to_sec("0:30:47")/6.21),curtime(),utc_time(),curdate(),utc_date(),utc_timestamp(),date_format("1997-01-02 03:04:05", "%M %W %D %Y %y %m %d %h %i %s %w"),from_unixtime(unix_timestamp("1994-03-02 10:11:12")),"1997-12-31 23:59:59" + INTERVAL 1 SECOND,"1998-01-01 00:00:00" - INTERVAL 1 SECOND,INTERVAL 1 DAY + "1997-12-31", extract(YEAR FROM "1999-01-02 10:11:12"),date_add("1997-12-31 23:59:59",INTERVAL 1 SECOND);
872 873
id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
1	SIMPLE	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	No tables used
874
Warnings:
875
Note	1003	select period_add('9602',-(12)) AS `period_add("9602",-12)`,period_diff(199505,'9404') AS `period_diff(199505,"9404")`,from_days(to_days('960101')) AS `from_days(to_days("960101"))`,dayofmonth('1997-01-02') AS `dayofmonth("1997-01-02")`,month('1997-01-02') AS `month("1997-01-02")`,monthname('1972-03-04') AS `monthname("1972-03-04")`,dayofyear('0000-00-00') AS `dayofyear("0000-00-00")`,hour('1997-03-03 23:03:22') AS `HOUR("1997-03-03 23:03:22")`,minute('23:03:22') AS `MINUTE("23:03:22")`,second(230322) AS `SECOND(230322)`,quarter(980303) AS `QUARTER(980303)`,week('1998-03-03',@@default_week_format) AS `WEEK("1998-03-03")`,yearweek('2000-01-01',1) AS `yearweek("2000-01-01",1)`,week(19950101,1) AS `week(19950101,1)`,year('98-02-03') AS `year("98-02-03")`,(weekday(curdate()) - weekday(now())) AS `weekday(curdate())-weekday(now())`,dayname('1962-03-03') AS `dayname("1962-03-03")`,unix_timestamp() AS `unix_timestamp()`,sec_to_time((time_to_sec('0:30:47') / 6.21)) AS `sec_to_time(time_to_sec("0:30:47")/6.21)`,curtime() AS `curtime()`,utc_time() AS `utc_time()`,curdate() AS `curdate()`,utc_date() AS `utc_date()`,utc_timestamp() AS `utc_timestamp()`,date_format('1997-01-02 03:04:05','%M %W %D %Y %y %m %d %h %i %s %w') AS `date_format("1997-01-02 03:04:05", "%M %W %D %Y %y %m %d %h %i %s %w")`,from_unixtime(unix_timestamp('1994-03-02 10:11:12')) AS `from_unixtime(unix_timestamp("1994-03-02 10:11:12"))`,('1997-12-31 23:59:59' + interval 1 second) AS `"1997-12-31 23:59:59" + INTERVAL 1 SECOND`,('1998-01-01 00:00:00' - interval 1 second) AS `"1998-01-01 00:00:00" - INTERVAL 1 SECOND`,('1997-12-31' + interval 1 day) AS `INTERVAL 1 DAY + "1997-12-31"`,extract(year from '1999-01-02 10:11:12') AS `extract(YEAR FROM "1999-01-02 10:11:12")`,('1997-12-31 23:59:59' + interval 1 second) AS `date_add("1997-12-31 23:59:59",INTERVAL 1 SECOND)`
876
SET @TMP='2007-08-01 12:22:49';
877
CREATE TABLE t1 (d DATETIME);
878 879 880
INSERT INTO t1 VALUES ('2007-08-01 12:22:59');
INSERT INTO t1 VALUES ('2007-08-01 12:23:01');
INSERT INTO t1 VALUES ('2007-08-01 12:23:20');
unknown's avatar
unknown committed
881
SELECT count(*) FROM t1 WHERE d>FROM_DAYS(TO_DAYS(@TMP)) AND d<=FROM_DAYS(TO_DAYS(@TMP)+1);
882 883 884
count(*)
3
DROP TABLE t1;
885 886 887 888 889 890 891 892
select last_day('2005-00-00');
last_day('2005-00-00')
NULL
select last_day('2005-00-01');
last_day('2005-00-01')
NULL
select last_day('2005-01-00');
last_day('2005-01-00')
Sergei Golubchik's avatar
merge  
Sergei Golubchik committed
893
2005-01-31
894 895 896 897
select monthname(str_to_date(null, '%m')), monthname(str_to_date(null, '%m')),
monthname(str_to_date(1, '%m')), monthname(str_to_date(0, '%m'));
monthname(str_to_date(null, '%m'))	monthname(str_to_date(null, '%m'))	monthname(str_to_date(1, '%m'))	monthname(str_to_date(0, '%m'))
NULL	NULL	January	NULL
898 899 900 901 902 903 904
set time_zone='-6:00';
create table t1(a timestamp);
insert into t1 values (19691231190001);
select * from t1;
a
1969-12-31 19:00:01
drop table t1;
905 906 907
create table t1(f1 date, f2 time, f3 datetime);
insert into t1 values ("2006-01-01", "12:01:01", "2006-01-01 12:01:01");
insert into t1 values ("2006-01-02", "12:01:02", "2006-01-02 12:01:02");
908
select f1 from t1 where f1 between CAST("2006-1-1" as date) and CAST(20060101 as date);
909 910
f1
2006-01-01
911
select f1 from t1 where f1 between cast("2006-1-1" as date) and cast("2006.1.1" as date);
912 913
f1
2006-01-01
914
select f1 from t1 where date(f1) between cast("2006-1-1" as date) and cast("2006.1.1" as date);
915 916
f1
2006-01-01
917
select f2 from t1 where f2 between cast("12:1:2" as time) and cast("12:2:2" as time);
918 919
f2
12:01:02
920
select f2 from t1 where time(f2) between cast("12:1:2" as time) and cast("12:2:2" as time);
921 922
f2
12:01:02
923
select f3 from t1 where f3 between cast("2006-1-1 12:1:1" as datetime) and cast("2006-1-1 12:1:2" as datetime);
924 925
f3
2006-01-01 12:01:01
926
select f3 from t1 where timestamp(f3) between cast("2006-1-1 12:1:1" as datetime) and cast("2006-1-1 12:1:2" as datetime);
927 928
f3
2006-01-01 12:01:01
929
select f1 from t1 where cast("2006-1-1" as date) between f1 and f3;
930 931
f1
2006-01-01
932
select f1 from t1 where cast("2006-1-1" as date) between date(f1) and date(f3);
933 934
f1
2006-01-01
unknown's avatar
unknown committed
935
select f1 from t1 where cast("2006-1-1" as date) between f1 and cast('zzz' as date);
936 937
f1
Warnings:
unknown's avatar
unknown committed
938
Warning	1292	Incorrect datetime value: 'zzz'
939 940 941 942 943 944 945
select f1 from t1 where makedate(2006,1) between date(f1) and date(f3);
f1
2006-01-01
select f1 from t1 where makedate(2006,2) between date(f1) and date(f3);
f1
2006-01-02
drop table t1;
unknown's avatar
unknown committed
946
create table t1 select now() - now(), curtime() - curtime(), 
947
sec_to_time(1) + 0, from_unixtime(1) + 0;
unknown's avatar
unknown committed
948 949 950
show create table t1;
Table	Create Table
t1	CREATE TABLE `t1` (
951 952
  `now() - now()` bigint(21) NOT NULL,
  `curtime() - curtime()` bigint(12) NOT NULL,
953 954
  `sec_to_time(1) + 0` bigint(12) DEFAULT NULL,
  `from_unixtime(1) + 0` bigint(21) DEFAULT NULL
unknown's avatar
unknown committed
955 956
) ENGINE=MyISAM DEFAULT CHARSET=latin1
drop table t1;
957 958 959 960 961 962 963
SELECT SEC_TO_TIME(3300000);
SEC_TO_TIME(3300000)
838:59:59
Warnings:
Warning	1292	Truncated incorrect time value: '3300000'
SELECT SEC_TO_TIME(3300000)+0;
SEC_TO_TIME(3300000)+0
964
8385959
965 966 967 968 969 970 971 972 973
Warnings:
Warning	1292	Truncated incorrect time value: '3300000'
SELECT SEC_TO_TIME(3600 * 4294967296);
SEC_TO_TIME(3600 * 4294967296)
838:59:59
Warnings:
Warning	1292	Truncated incorrect time value: '15461882265600'
SELECT TIME_TO_SEC('916:40:00');
TIME_TO_SEC('916:40:00')
Sergei Golubchik's avatar
Sergei Golubchik committed
974
3020399
975 976 977 978
Warnings:
Warning	1292	Truncated incorrect time value: '916:40:00'
SELECT ADDTIME('500:00:00', '416:40:00');
ADDTIME('500:00:00', '416:40:00')
979
838:59:59.999999
980 981 982 983
Warnings:
Warning	1292	Truncated incorrect time value: '916:40:00'
SELECT ADDTIME('916:40:00', '416:40:00');
ADDTIME('916:40:00', '416:40:00')
984
838:59:59.999999
985 986
Warnings:
Warning	1292	Truncated incorrect time value: '916:40:00'
987
Warning	1292	Truncated incorrect time value: '1255:39:59.999999'
988 989
SELECT SUBTIME('916:40:00', '416:40:00');
SUBTIME('916:40:00', '416:40:00')
990
422:19:59.999999
991 992 993 994
Warnings:
Warning	1292	Truncated incorrect time value: '916:40:00'
SELECT SUBTIME('-916:40:00', '416:40:00');
SUBTIME('-916:40:00', '416:40:00')
995
-838:59:59.999999
996 997
Warnings:
Warning	1292	Truncated incorrect time value: '-916:40:00'
998
Warning	1292	Truncated incorrect time value: '-1255:39:59.999999'
999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023
SELECT MAKETIME(916,0,0);
MAKETIME(916,0,0)
838:59:59
Warnings:
Warning	1292	Truncated incorrect time value: '916:00:00'
SELECT MAKETIME(4294967296, 0, 0);
MAKETIME(4294967296, 0, 0)
838:59:59
Warnings:
Warning	1292	Truncated incorrect time value: '4294967296:00:00'
SELECT MAKETIME(-4294967296, 0, 0);
MAKETIME(-4294967296, 0, 0)
-838:59:59
Warnings:
Warning	1292	Truncated incorrect time value: '-4294967296:00:00'
SELECT MAKETIME(0, 4294967296, 0);
MAKETIME(0, 4294967296, 0)
NULL
SELECT MAKETIME(0, 0, 4294967296);
MAKETIME(0, 0, 4294967296)
NULL
SELECT MAKETIME(CAST(-1 AS UNSIGNED), 0, 0);
MAKETIME(CAST(-1 AS UNSIGNED), 0, 0)
838:59:59
Warnings:
Sergei Golubchik's avatar
Sergei Golubchik committed
1024
Note	1105	Cast to unsigned converted negative integer to it's positive complement
1025
Warning	1292	Truncated incorrect time value: '18446744073709551615:00:00'
1026 1027
SELECT EXTRACT(HOUR FROM '10000:02:03');
EXTRACT(HOUR FROM '10000:02:03')
1028
22
1029
Warnings:
1030
Warning	1292	Truncated incorrect time value: '10000:02:03'
1031 1032 1033 1034
CREATE TABLE t1(f1 TIME);
INSERT INTO t1 VALUES('916:00:00 a');
Warnings:
Warning	1265	Data truncated for column 'f1' at row 1
unknown's avatar
unknown committed
1035
Warning	1264	Out of range value for column 'f1' at row 1
1036 1037 1038 1039 1040 1041 1042 1043
SELECT * FROM t1;
f1
838:59:59
DROP TABLE t1;
SELECT SEC_TO_TIME(CAST(-1 AS UNSIGNED));
SEC_TO_TIME(CAST(-1 AS UNSIGNED))
838:59:59
Warnings:
Sergei Golubchik's avatar
Sergei Golubchik committed
1044 1045
Note	1105	Cast to unsigned converted negative integer to it's positive complement
Note	1105	Cast to unsigned converted negative integer to it's positive complement
1046
Warning	1292	Truncated incorrect time value: '18446744073709551615'
1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058
SET NAMES latin1;
SET character_set_results = NULL;
SHOW VARIABLES LIKE 'character_set_results';
Variable_name	Value
character_set_results	
CREATE TABLE testBug8868 (field1 DATE, field2 VARCHAR(32) CHARACTER SET BINARY);
INSERT INTO testBug8868 VALUES ('2006-09-04', 'abcd');
SELECT DATE_FORMAT(field1,'%b-%e %l:%i%p') as fmtddate, field2 FROM testBug8868;
fmtddate	field2
Sep-4 12:00AM	abcd
DROP TABLE testBug8868;
SET NAMES DEFAULT;
1059 1060 1061 1062 1063 1064 1065 1066 1067
CREATE TABLE t1 (
a TIMESTAMP
);
INSERT INTO t1 VALUES (now()), (now());
SELECT 1 FROM t1 ORDER BY MAKETIME(1, 1, a);
1
1
1
DROP TABLE t1;
1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087
(select time_format(timediff(now(), DATE_SUB(now(),INTERVAL 5 DAY)),'%H') As H)
union
(select time_format(timediff(now(), DATE_SUB(now(),INTERVAL 5 DAY)),'%H') As H);
H
120
(select time_format(timediff(now(), DATE_SUB(now(),INTERVAL 5 DAY)),'%k') As H)
union
(select time_format(timediff(now(), DATE_SUB(now(),INTERVAL 5 DAY)),'%k') As H);
H
120
(select time_format(timediff(now(), DATE_SUB(now(),INTERVAL 5 HOUR)),'%H') As H)
union
(select time_format(timediff(now(), DATE_SUB(now(),INTERVAL 5 HOUR)),'%H') As H);
H
05
(select time_format(timediff(now(), DATE_SUB(now(),INTERVAL 5 HOUR)),'%k') As H)
union
(select time_format(timediff(now(), DATE_SUB(now(),INTERVAL 5 HOUR)),'%k') As H);
H
5
1088 1089 1090
select last_day('0000-00-00');
last_day('0000-00-00')
NULL
1091 1092 1093
select isnull(week(now() + 0)), isnull(week(now() + 0.2)),
week(20061108), week(20061108.01), week(20061108085411.000002);
isnull(week(now() + 0))	isnull(week(now() + 0.2))	week(20061108)	week(20061108.01)	week(20061108085411.000002)
1094
0	0	45	45	45
1095
Warnings:
1096
Warning	1292	Truncated incorrect datetime value: '20061108.01'
1097
End of 4.1 tests
1098 1099 1100
select time_format('100:00:00', '%H %k %h %I %l');
time_format('100:00:00', '%H %k %h %I %l')
100 100 04 04 4
1101
SET @old_log_bin_trust_function_creators= @@global.log_bin_trust_function_creators;
1102
SET GLOBAL log_bin_trust_function_creators = 1;
1103 1104
create table t1 (a timestamp default '2005-05-05 01:01:01',
b timestamp default '2005-05-05 01:01:01');
1105
drop function if exists t_slow_sysdate;
1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125
create function t_slow_sysdate() returns timestamp
begin
do sleep(2);
return sysdate();
end;
//
insert into t1 set a = sysdate(), b = t_slow_sysdate();//
create trigger t_before before insert on t1
for each row begin
set new.b = t_slow_sysdate();
end
//
insert into t1 set a = sysdate();
select a != b from t1;
a != b
1
1
drop trigger t_before;
drop function t_slow_sysdate;
drop table t1;
1126
SET GLOBAL log_bin_trust_function_creators = 0;
1127
create table t1 (a datetime, i int, b datetime);
1128
insert into t1 select sysdate(), sleep(2), sysdate() from dual;
1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144
select a != b from t1;
a != b
1
drop table t1;
create procedure t_sysdate()
begin
select sysdate() into @a;
do sleep(2);
select sysdate() into @b;
select @a != @b;
end;
//
call t_sysdate();
@a != @b
1
drop procedure t_sysdate;
1145
SET @@global.log_bin_trust_function_creators= @old_log_bin_trust_function_creators;
1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196
select timestampdiff(month,'2004-09-11','2004-09-11');
timestampdiff(month,'2004-09-11','2004-09-11')
0
select timestampdiff(month,'2004-09-11','2005-09-11');
timestampdiff(month,'2004-09-11','2005-09-11')
12
select timestampdiff(month,'2004-09-11','2006-09-11');
timestampdiff(month,'2004-09-11','2006-09-11')
24
select timestampdiff(month,'2004-09-11','2007-09-11');
timestampdiff(month,'2004-09-11','2007-09-11')
36
select timestampdiff(month,'2005-09-11','2004-09-11');
timestampdiff(month,'2005-09-11','2004-09-11')
-12
select timestampdiff(month,'2005-09-11','2003-09-11');
timestampdiff(month,'2005-09-11','2003-09-11')
-24
select timestampdiff(month,'2004-02-28','2005-02-28');
timestampdiff(month,'2004-02-28','2005-02-28')
12
select timestampdiff(month,'2004-02-29','2005-02-28');
timestampdiff(month,'2004-02-29','2005-02-28')
11
select timestampdiff(month,'2004-02-28','2005-02-28');
timestampdiff(month,'2004-02-28','2005-02-28')
12
select timestampdiff(month,'2004-03-29','2005-03-28');
timestampdiff(month,'2004-03-29','2005-03-28')
11
select timestampdiff(month,'2003-02-28','2004-02-29');
timestampdiff(month,'2003-02-28','2004-02-29')
12
select timestampdiff(month,'2003-02-28','2005-02-28');
timestampdiff(month,'2003-02-28','2005-02-28')
24
select timestampdiff(month,'1999-09-11','2001-10-10');
timestampdiff(month,'1999-09-11','2001-10-10')
24
select timestampdiff(month,'1999-09-11','2001-9-11');
timestampdiff(month,'1999-09-11','2001-9-11')
24
select timestampdiff(year,'1999-09-11','2001-9-11');
timestampdiff(year,'1999-09-11','2001-9-11')
2
select timestampdiff(year,'2004-02-28','2005-02-28');
timestampdiff(year,'2004-02-28','2005-02-28')
1
select timestampdiff(year,'2004-02-29','2005-02-28');
timestampdiff(year,'2004-02-29','2005-02-28')
0
unknown's avatar
unknown committed
1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221
CREATE TABLE t1 (id int NOT NULL PRIMARY KEY, day date);
CREATE TABLE t2 (id int NOT NULL PRIMARY KEY, day date);
INSERT INTO t1 VALUES
(1, '2005-06-01'), (2, '2005-02-01'), (3, '2005-07-01');
INSERT INTO t2 VALUES
(1, '2005-08-01'), (2, '2005-06-15'), (3, '2005-07-15');
SELECT * FROM t1, t2 
WHERE t1.day BETWEEN 
'2005.09.01' - INTERVAL 6 MONTH AND t2.day;
id	day	id	day
1	2005-06-01	1	2005-08-01
3	2005-07-01	1	2005-08-01
1	2005-06-01	2	2005-06-15
1	2005-06-01	3	2005-07-15
3	2005-07-01	3	2005-07-15
SELECT * FROM t1, t2 
WHERE CAST(t1.day AS DATE) BETWEEN 
'2005.09.01' - INTERVAL 6 MONTH AND t2.day;
id	day	id	day
1	2005-06-01	1	2005-08-01
3	2005-07-01	1	2005-08-01
1	2005-06-01	2	2005-06-15
1	2005-06-01	3	2005-07-15
3	2005-07-01	3	2005-07-15
DROP TABLE t1,t2;
1222
set time_zone= @@global.time_zone;
1223 1224
select str_to_date('10:00 PM', '%h:%i %p') + INTERVAL 10 MINUTE;
str_to_date('10:00 PM', '%h:%i %p') + INTERVAL 10 MINUTE
1225
22:10:00
Sergei Golubchik's avatar
Sergei Golubchik committed
1226 1227 1228 1229
select str_to_date("1997-00-04 22:23:00","%Y-%m-%D") + interval 10 minute;
str_to_date("1997-00-04 22:23:00","%Y-%m-%D") + interval 10 minute
NULL
Warnings:
1230 1231
Warning	1292	Truncated incorrect date value: '1997-00-04 22:23:00'
Warning	1292	Incorrect datetime value: '1997-00-04'
1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248
create table t1 (field DATE);
insert into t1 values ('2006-11-06');
select * from t1 where field < '2006-11-06 04:08:36.0';
field
2006-11-06
select * from t1 where field = '2006-11-06 04:08:36.0';
field
select * from t1 where field = '2006-11-06';
field
2006-11-06
select * from t1 where CAST(field as DATETIME) < '2006-11-06 04:08:36.0';
field
2006-11-06
select * from t1 where CAST(field as DATE) < '2006-11-06 04:08:36.0';
field
2006-11-06
drop table t1;
1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262
CREATE TABLE t1 (a int, t1 time, t2 time, d date, PRIMARY KEY  (a));
INSERT INTO t1 VALUES (1, '10:00:00', NULL, NULL), 
(2, '11:00:00', '11:15:00', '1972-02-06');
SELECT t1, t2, SEC_TO_TIME( TIME_TO_SEC( t2 ) - TIME_TO_SEC( t1 ) ), QUARTER(d) 
FROM t1;
t1	t2	SEC_TO_TIME( TIME_TO_SEC( t2 ) - TIME_TO_SEC( t1 ) )	QUARTER(d)
10:00:00	NULL	NULL	NULL
11:00:00	11:15:00	00:15:00	1
SELECT t1, t2, SEC_TO_TIME( TIME_TO_SEC( t2 ) - TIME_TO_SEC( t1 ) ), QUARTER(d)
FROM t1 ORDER BY a DESC;
t1	t2	SEC_TO_TIME( TIME_TO_SEC( t2 ) - TIME_TO_SEC( t1 ) )	QUARTER(d)
11:00:00	11:15:00	00:15:00	1
10:00:00	NULL	NULL	NULL
DROP TABLE t1;
1263 1264 1265 1266
SELECT TIME_FORMAT(SEC_TO_TIME(a),"%H:%i:%s") FROM (SELECT 3020399 AS a UNION SELECT 3020398 ) x GROUP BY 1;
TIME_FORMAT(SEC_TO_TIME(a),"%H:%i:%s")
838:59:58
838:59:59
1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281
set names latin1;
create table t1 (a varchar(15) character set ascii not null);
insert into t1 values ('070514-000000');
select concat(a,ifnull(min(date_format(now(), '%Y-%m-%d')),' ull')) from t1;
concat(a,ifnull(min(date_format(now(), '%Y-%m-%d')),' ull'))
#
set names swe7;
select concat(a,ifnull(min(date_format(now(), '%Y-%m-%d')),' ull')) from t1;
ERROR HY000: Illegal mix of collations (ascii_general_ci,IMPLICIT) and (swe7_swedish_ci,COERCIBLE) for operation 'concat'
set names latin1;
set lc_time_names=fr_FR;
select concat(a,ifnull(min(date_format(now(), '%Y-%m-%d')),' ull')) from t1;
ERROR HY000: Illegal mix of collations (ascii_general_ci,IMPLICIT) and (latin1_swedish_ci,COERCIBLE) for operation 'concat'
set lc_time_names=en_US;
drop table t1;
1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293
select DATE_ADD('20071108181000', INTERVAL 1 DAY);
DATE_ADD('20071108181000', INTERVAL 1 DAY)
2007-11-09 18:10:00
select DATE_ADD(20071108181000,   INTERVAL 1 DAY);
DATE_ADD(20071108181000,   INTERVAL 1 DAY)
2007-11-09 18:10:00
select DATE_ADD('20071108',       INTERVAL 1 DAY);
DATE_ADD('20071108',       INTERVAL 1 DAY)
2007-11-09
select DATE_ADD(20071108,         INTERVAL 1 DAY);
DATE_ADD(20071108,         INTERVAL 1 DAY)
2007-11-09
1294 1295 1296
select LAST_DAY('2007-12-06 08:59:19.05') - INTERVAL 1 SECOND;
LAST_DAY('2007-12-06 08:59:19.05') - INTERVAL 1 SECOND
2007-12-30 23:59:59
1297 1298 1299 1300 1301 1302
select date_add('1000-01-01 00:00:00', interval '1.03:02:01.05' day_microsecond);
date_add('1000-01-01 00:00:00', interval '1.03:02:01.05' day_microsecond)
1000-01-02 03:02:01.050000
select date_add('1000-01-01 00:00:00', interval '1.02' day_microsecond);
date_add('1000-01-01 00:00:00', interval '1.02' day_microsecond)
1000-01-01 00:00:01.020000
1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319
#
# Bug #52315 part 2 : utc_date() crashes when system time > year 2037
#
SET TIMESTAMP=-147490000;
SELECT UTC_TIMESTAMP();
SET TIMESTAMP=2147483648;
SELECT UTC_TIMESTAMP();
SET TIMESTAMP=2147483646;
SELECT UTC_TIMESTAMP();
SET TIMESTAMP=2147483647;
SELECT UTC_TIMESTAMP();
SET TIMESTAMP=0;
SELECT UTC_TIMESTAMP();
SET TIMESTAMP=-1;
SELECT UTC_TIMESTAMP();
SET TIMESTAMP=1;
SELECT UTC_TIMESTAMP();
Georgi Kodinov's avatar
merge  
Georgi Kodinov committed
1320
SET TIMESTAMP=0;
1321 1322 1323
End of 5.0 tests
select date_sub("0050-01-01 00:00:01",INTERVAL 2 SECOND);
date_sub("0050-01-01 00:00:01",INTERVAL 2 SECOND)
1324
0049-12-31 23:59:59
1325 1326
select date_sub("0199-01-01 00:00:01",INTERVAL 2 SECOND);
date_sub("0199-01-01 00:00:01",INTERVAL 2 SECOND)
1327
0198-12-31 23:59:59
1328 1329
select date_add("0199-12-31 23:59:59",INTERVAL 2 SECOND);
date_add("0199-12-31 23:59:59",INTERVAL 2 SECOND)
1330
0200-01-01 00:00:01
1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350
select date_sub("0200-01-01 00:00:01",INTERVAL 2 SECOND);
date_sub("0200-01-01 00:00:01",INTERVAL 2 SECOND)
0199-12-31 23:59:59
select date_sub("0200-01-01 00:00:01",INTERVAL 1 SECOND);
date_sub("0200-01-01 00:00:01",INTERVAL 1 SECOND)
0200-01-01 00:00:00
select date_sub("0200-01-01 00:00:01",INTERVAL 2 SECOND);
date_sub("0200-01-01 00:00:01",INTERVAL 2 SECOND)
0199-12-31 23:59:59
select date_add("2001-01-01 23:59:59",INTERVAL -2000 YEAR);
date_add("2001-01-01 23:59:59",INTERVAL -2000 YEAR)
0001-01-01 23:59:59
select date_sub("50-01-01 00:00:01",INTERVAL 2 SECOND);
date_sub("50-01-01 00:00:01",INTERVAL 2 SECOND)
2049-12-31 23:59:59
select date_sub("90-01-01 00:00:01",INTERVAL 2 SECOND);
date_sub("90-01-01 00:00:01",INTERVAL 2 SECOND)
1989-12-31 23:59:59
select date_sub("0069-01-01 00:00:01",INTERVAL 2 SECOND);
date_sub("0069-01-01 00:00:01",INTERVAL 2 SECOND)
1351
0068-12-31 23:59:59
1352 1353
select date_sub("0169-01-01 00:00:01",INTERVAL 2 SECOND);
date_sub("0169-01-01 00:00:01",INTERVAL 2 SECOND)
1354
0168-12-31 23:59:59
1355 1356 1357 1358 1359 1360 1361 1362
CREATE TABLE t1(a DOUBLE NOT NULL);
INSERT INTO t1 VALUES (0),(9.216e-096);
# should not crash
SELECT 1 FROM t1 ORDER BY @x:=makedate(a,a);
1
1
1
DROP TABLE t1;
1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376
#
# Bug #52160: crash and inconsistent results when grouping
#             by a function and column
#
CREATE TABLE t1(a CHAR(10) NOT NULL);
INSERT INTO t1 VALUES (''),('');
SELECT COUNT(*) FROM t1 GROUP BY TIME_TO_SEC(a);
COUNT(*)
2
Warnings:
Warning	1292	Truncated incorrect time value: ''
Warning	1292	Truncated incorrect time value: ''
Warning	1292	Truncated incorrect time value: ''
DROP TABLE t1;
1377 1378 1379 1380 1381 1382
#
# Bug#11766112  59151:UNINITIALIZED VALUES IN EXTRACT_DATE_TIME WITH STR_TO_DATE(SPACE(..) ...
#
SELECT STR_TO_DATE(SPACE(2),'1');
STR_TO_DATE(SPACE(2),'1')
0000-00-00
1383 1384 1385 1386 1387 1388
#
# Bug#11765216  58154: UNINITIALIZED VARIABLE FORMAT IN STR_TO_DATE FUNCTION
#
SET GLOBAL SQL_MODE='';
DO  STR_TO_DATE((''), FROM_DAYS(@@GLOBAL.SQL_MODE));
SET GLOBAL SQL_MODE=DEFAULT;
1389 1390 1391 1392 1393 1394
#
# Bug#11766087  59125: VALGRIND UNINITIALISED VALUE WARNING IN ULL2DEC, LONGLONG2DECIMAL
#
SELECT FORMAT(YEAR(STR_TO_DATE('',GET_FORMAT(TIME,''))),1);
FORMAT(YEAR(STR_TO_DATE('',GET_FORMAT(TIME,''))),1)
NULL
1395 1396 1397 1398
#
# Bug#11766126  59166: ANOTHER DATETIME VALGRIND UNINITIALIZED WARNING
#
SELECT CAST((MONTH(FROM_UNIXTIME(@@GLOBAL.SQL_MODE))) AS BINARY(1025));
1399 1400 1401 1402 1403 1404
#
# Bug#11766124  59164: VALGRIND: UNINITIALIZED VALUE IN NUMBER_TO_DATETIME
#
SELECT ADDDATE(MONTH(FROM_UNIXTIME(NULL)),INTERVAL 1 HOUR);
ADDDATE(MONTH(FROM_UNIXTIME(NULL)),INTERVAL 1 HOUR)
NULL
1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416
#
# Bug#11889186  60503: CRASH IN MAKE_DATE_TIME WITH DATE_FORMAT / STR_TO_DATE COMBINATION
#
SELECT DATE_FORMAT('0000-00-11', '%W');
DATE_FORMAT('0000-00-11', '%W')
NULL
SELECT DATE_FORMAT('0000-00-11', '%a');
DATE_FORMAT('0000-00-11', '%a')
NULL
SELECT DATE_FORMAT('0000-00-11', '%w');
DATE_FORMAT('0000-00-11', '%w')
NULL
1417 1418 1419 1420 1421 1422 1423 1424
#
# Bug#12403504  AFTER FIX FOR #11889186 : ASSERTION FAILED: DELSUM+(INT) Y/4-TEMP > 0
#
SELECT MAKEDATE(11111111,1);
MAKEDATE(11111111,1)
NULL
SELECT WEEK(DATE_ADD(FROM_DAYS(1),INTERVAL 1 MONTH), 1);
WEEK(DATE_ADD(FROM_DAYS(1),INTERVAL 1 MONTH), 1)
1425 1426 1427
NULL
Warnings:
Warning	1292	Incorrect datetime value: '0000-00-00'
1428 1429 1430 1431 1432
#
# Bug#12584302 AFTER FIX FOR #12403504: ASSERTION FAILED: DELSUM+(INT) Y/4-TEMP > 0,
#
DO WEEK((DATE_ADD((CAST(0 AS DATE)), INTERVAL 1 YEAR_MONTH)), 5);
Warnings:
1433
Warning	1292	Incorrect datetime value: '0000-00-00'
1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466
#
# BUG#13458237 INCONSISTENT HANDLING OF INVALIDE DATES WITH ZERO DAY
# SIMILAR TO '2009-10-00' 
#
SELECT
DATE('20091000'),
STR_TO_DATE('200910','%Y%m'),
LAST_DAY('2009-10-00'),
LAST_DAY(DATE('2009-10-00')),
LAST_DAY(DATE'2009-10-00'),
LAST_DAY(STR_TO_DATE('200910','%Y%m')),
WEEK('2009-10-00'),
WEEK(DATE('2009-10-00')),
WEEK(DATE'2009-10-00'),
WEEK(STR_TO_DATE('200910','%Y%m')),
WEEKOFYEAR('2009-10-00'),
WEEKOFYEAR(DATE('2009-10-00')),
WEEKOFYEAR(DATE'2009-10-00'),
WEEKOFYEAR(STR_TO_DATE('200910','%Y%m')),
DAYOFYEAR('2009-10-00'),
DAYOFYEAR(DATE('2009-10-00')),
DAYOFYEAR(DATE'2009-10-00'),
DAYOFYEAR(STR_TO_DATE('200910','%Y%m')),
WEEKDAY('2009-10-00'),
WEEKDAY(DATE('2009-10-00')),
WEEKDAY(DATE'2009-10-00'),
WEEKDAY(STR_TO_DATE('200910','%Y%m')),
TO_DAYs('2009-10-00'),
TO_DAYs(DATE('2009-10-00')),
TO_DAYs(DATE'2009-10-00'),
TO_DAYs(STR_TO_DATE('200910','%Y%m'));
DATE('20091000')	2009-10-00
STR_TO_DATE('200910','%Y%m')	2009-10-00
Sergei Golubchik's avatar
merge  
Sergei Golubchik committed
1467
LAST_DAY('2009-10-00')	2009-10-31
1468
LAST_DAY(DATE('2009-10-00'))	2009-10-31
Sergei Golubchik's avatar
merge  
Sergei Golubchik committed
1469
LAST_DAY(DATE'2009-10-00')	2009-10-31
1470 1471
LAST_DAY(STR_TO_DATE('200910','%Y%m'))	2009-10-31
WEEK('2009-10-00')	NULL
Sergei Golubchik's avatar
Sergei Golubchik committed
1472
WEEK(DATE('2009-10-00'))	NULL
1473 1474 1475
WEEK(DATE'2009-10-00')	NULL
WEEK(STR_TO_DATE('200910','%Y%m'))	NULL
WEEKOFYEAR('2009-10-00')	NULL
Sergei Golubchik's avatar
Sergei Golubchik committed
1476
WEEKOFYEAR(DATE('2009-10-00'))	NULL
1477 1478 1479
WEEKOFYEAR(DATE'2009-10-00')	NULL
WEEKOFYEAR(STR_TO_DATE('200910','%Y%m'))	NULL
DAYOFYEAR('2009-10-00')	NULL
Sergei Golubchik's avatar
Sergei Golubchik committed
1480
DAYOFYEAR(DATE('2009-10-00'))	NULL
1481 1482 1483
DAYOFYEAR(DATE'2009-10-00')	NULL
DAYOFYEAR(STR_TO_DATE('200910','%Y%m'))	NULL
WEEKDAY('2009-10-00')	NULL
Sergei Golubchik's avatar
Sergei Golubchik committed
1484
WEEKDAY(DATE('2009-10-00'))	NULL
1485 1486 1487
WEEKDAY(DATE'2009-10-00')	NULL
WEEKDAY(STR_TO_DATE('200910','%Y%m'))	NULL
TO_DAYs('2009-10-00')	NULL
Sergei Golubchik's avatar
Sergei Golubchik committed
1488
TO_DAYs(DATE('2009-10-00'))	NULL
1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501
TO_DAYs(DATE'2009-10-00')	NULL
TO_DAYs(STR_TO_DATE('200910','%Y%m'))	NULL
Warnings:
Level	Warning
Code	1292
Message	Incorrect datetime value: '2009-10-00'
Level	Warning
Code	1292
Message	Incorrect datetime value: '2009-10-00'
Level	Warning
Code	1292
Message	Incorrect datetime value: '2009-10-00'
Level	Warning
1502 1503 1504
Code	1411
Message	Incorrect datetime value: '200910' for function str_to_date
Level	Warning
1505 1506 1507 1508 1509
Code	1292
Message	Incorrect datetime value: '2009-10-00'
Level	Warning
Code	1292
Message	Incorrect datetime value: '2009-10-00'
Sergei Golubchik's avatar
Sergei Golubchik committed
1510 1511
Level	Warning
Code	1292
1512 1513
Message	Incorrect datetime value: '2009-10-00'
Level	Warning
1514 1515 1516
Code	1411
Message	Incorrect datetime value: '200910' for function str_to_date
Level	Warning
1517 1518 1519 1520 1521
Code	1292
Message	Incorrect datetime value: '2009-10-00'
Level	Warning
Code	1292
Message	Incorrect datetime value: '2009-10-00'
Sergei Golubchik's avatar
Sergei Golubchik committed
1522 1523
Level	Warning
Code	1292
1524 1525
Message	Incorrect datetime value: '2009-10-00'
Level	Warning
1526 1527 1528
Code	1411
Message	Incorrect datetime value: '200910' for function str_to_date
Level	Warning
1529 1530 1531 1532 1533
Code	1292
Message	Incorrect datetime value: '2009-10-00'
Level	Warning
Code	1292
Message	Incorrect datetime value: '2009-10-00'
Sergei Golubchik's avatar
Sergei Golubchik committed
1534 1535
Level	Warning
Code	1292
1536 1537
Message	Incorrect datetime value: '2009-10-00'
Level	Warning
1538 1539 1540
Code	1411
Message	Incorrect datetime value: '200910' for function str_to_date
Level	Warning
1541 1542 1543 1544
Code	1292
Message	Incorrect datetime value: '2009-10-00'
Level	Warning
Code	1292
Sergei Golubchik's avatar
merge  
Sergei Golubchik committed
1545
Message	Incorrect datetime value: '2009-10-00'
Sergei Golubchik's avatar
Sergei Golubchik committed
1546 1547
Level	Warning
Code	1292
1548
Message	Incorrect datetime value: '2009-10-00'
1549 1550 1551
Level	Warning
Code	1411
Message	Incorrect datetime value: '200910' for function str_to_date
1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580
SELECT
DATE('00000100'),
STR_TO_DATE('000001','%Y%m'),
LAST_DAY('0000-01-00'),
LAST_DAY(DATE('0000-01-00')),
LAST_DAY(DATE'0000-01-00'),
LAST_DAY(STR_TO_DATE('000001','%Y%m')),
WEEK('0000-01-00'),
WEEK(DATE('0000-01-00')),
WEEK(DATE'0000-01-00'),
WEEK(STR_TO_DATE('000001','%Y%m')),
WEEKOFYEAR('0000-01-00'),
WEEKOFYEAR(DATE('0000-01-00')),
WEEKOFYEAR(DATE'0000-01-00'),
WEEKOFYEAR(STR_TO_DATE('000001','%Y%m')),
DAYOFYEAR('0000-01-00'),
DAYOFYEAR(DATE('0000-01-00')),
DAYOFYEAR(DATE'0000-01-00'),
DAYOFYEAR(STR_TO_DATE('000001','%Y%m')),
WEEKDAY('0000-01-00'),
WEEKDAY(DATE('0000-01-00')),
WEEKDAY(DATE'0000-01-00'),
WEEKDAY(STR_TO_DATE('000001','%Y%m')),
TO_DAYs('0000-01-00'),
TO_DAYs(DATE('0000-01-00')),
TO_DAYs(DATE'0000-01-00'),
TO_DAYs(STR_TO_DATE('000001','%Y%m'));
DATE('00000100')	0000-01-00
STR_TO_DATE('000001','%Y%m')	0000-01-00
Sergei Golubchik's avatar
merge  
Sergei Golubchik committed
1581
LAST_DAY('0000-01-00')	0000-01-31
1582
LAST_DAY(DATE('0000-01-00'))	0000-01-31
Sergei Golubchik's avatar
merge  
Sergei Golubchik committed
1583
LAST_DAY(DATE'0000-01-00')	0000-01-31
1584 1585
LAST_DAY(STR_TO_DATE('000001','%Y%m'))	0000-01-31
WEEK('0000-01-00')	NULL
Sergei Golubchik's avatar
Sergei Golubchik committed
1586
WEEK(DATE('0000-01-00'))	NULL
1587 1588 1589
WEEK(DATE'0000-01-00')	NULL
WEEK(STR_TO_DATE('000001','%Y%m'))	NULL
WEEKOFYEAR('0000-01-00')	NULL
Sergei Golubchik's avatar
Sergei Golubchik committed
1590
WEEKOFYEAR(DATE('0000-01-00'))	NULL
1591 1592 1593
WEEKOFYEAR(DATE'0000-01-00')	NULL
WEEKOFYEAR(STR_TO_DATE('000001','%Y%m'))	NULL
DAYOFYEAR('0000-01-00')	NULL
Sergei Golubchik's avatar
Sergei Golubchik committed
1594
DAYOFYEAR(DATE('0000-01-00'))	NULL
1595 1596 1597
DAYOFYEAR(DATE'0000-01-00')	NULL
DAYOFYEAR(STR_TO_DATE('000001','%Y%m'))	NULL
WEEKDAY('0000-01-00')	NULL
Sergei Golubchik's avatar
Sergei Golubchik committed
1598
WEEKDAY(DATE('0000-01-00'))	NULL
1599 1600 1601
WEEKDAY(DATE'0000-01-00')	NULL
WEEKDAY(STR_TO_DATE('000001','%Y%m'))	NULL
TO_DAYs('0000-01-00')	NULL
Sergei Golubchik's avatar
Sergei Golubchik committed
1602
TO_DAYs(DATE('0000-01-00'))	NULL
1603 1604
TO_DAYs(DATE'0000-01-00')	NULL
TO_DAYs(STR_TO_DATE('000001','%Y%m'))	NULL
1605
Warnings:
1606 1607 1608 1609 1610 1611 1612 1613 1614 1615
Level	Warning
Code	1292
Message	Incorrect datetime value: '0000-01-00'
Level	Warning
Code	1292
Message	Incorrect datetime value: '0000-01-00'
Level	Warning
Code	1292
Message	Incorrect datetime value: '0000-01-00'
Level	Warning
1616 1617 1618
Code	1411
Message	Incorrect datetime value: '000001' for function str_to_date
Level	Warning
1619 1620 1621 1622 1623
Code	1292
Message	Incorrect datetime value: '0000-01-00'
Level	Warning
Code	1292
Message	Incorrect datetime value: '0000-01-00'
Sergei Golubchik's avatar
Sergei Golubchik committed
1624 1625
Level	Warning
Code	1292
1626 1627
Message	Incorrect datetime value: '0000-01-00'
Level	Warning
1628 1629 1630
Code	1411
Message	Incorrect datetime value: '000001' for function str_to_date
Level	Warning
1631 1632 1633 1634 1635
Code	1292
Message	Incorrect datetime value: '0000-01-00'
Level	Warning
Code	1292
Message	Incorrect datetime value: '0000-01-00'
Sergei Golubchik's avatar
Sergei Golubchik committed
1636 1637
Level	Warning
Code	1292
1638 1639
Message	Incorrect datetime value: '0000-01-00'
Level	Warning
1640 1641 1642
Code	1411
Message	Incorrect datetime value: '000001' for function str_to_date
Level	Warning
1643 1644 1645 1646 1647
Code	1292
Message	Incorrect datetime value: '0000-01-00'
Level	Warning
Code	1292
Message	Incorrect datetime value: '0000-01-00'
Sergei Golubchik's avatar
Sergei Golubchik committed
1648 1649
Level	Warning
Code	1292
1650 1651
Message	Incorrect datetime value: '0000-01-00'
Level	Warning
1652 1653 1654
Code	1411
Message	Incorrect datetime value: '000001' for function str_to_date
Level	Warning
1655 1656 1657 1658
Code	1292
Message	Incorrect datetime value: '0000-01-00'
Level	Warning
Code	1292
Sergei Golubchik's avatar
merge  
Sergei Golubchik committed
1659
Message	Incorrect datetime value: '0000-01-00'
Sergei Golubchik's avatar
Sergei Golubchik committed
1660 1661
Level	Warning
Code	1292
1662
Message	Incorrect datetime value: '0000-01-00'
1663 1664 1665
Level	Warning
Code	1411
Message	Incorrect datetime value: '000001' for function str_to_date
1666
End of 5.1 tests
1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677
#
# Bug#57039: constant subtime expression returns incorrect result.
#
CREATE TABLE t1 (`date_date` datetime NOT NULL);
INSERT INTO t1 VALUES ('2008-01-03 00:00:00'), ('2008-01-03 00:00:00');
SELECT * FROM t1 WHERE date_date >= subtime(now(), "00:30:00");
date_date
SELECT * FROM t1 WHERE date_date <= addtime(date_add("2000-1-1", INTERVAL "1:1:1" HOUR_SECOND), "00:20:00");
date_date
DROP TABLE t1;
#
1678 1679 1680 1681 1682 1683 1684 1685 1686
# Bug#57512 str_to_date crash...
#
SELECT WEEK(STR_TO_DATE(NULL,0));
WEEK(STR_TO_DATE(NULL,0))
NULL
SELECT SUBDATE(STR_TO_DATE(NULL,0), INTERVAL 1 HOUR);
SUBDATE(STR_TO_DATE(NULL,0), INTERVAL 1 HOUR)
NULL
#
1687 1688 1689 1690 1691 1692 1693 1694
# BUG#59895 - setting storage engine to null segfaults mysqld
#
SELECT MONTHNAME(0), MONTHNAME(0) IS NULL, MONTHNAME(0) + 1;
MONTHNAME(0)	MONTHNAME(0) IS NULL	MONTHNAME(0) + 1
NULL	1	NULL
SET storage_engine=NULL;
ERROR 42000: Variable 'storage_engine' can't be set to the value of 'NULL'
#
1695 1696 1697 1698 1699 1700 1701 1702 1703
# BUG#13354387 - CRASH IN IN MY_DECIMAL::OPERATOR FOR VIEW AND FUNCTION UNIX_TIMESTAMP 
# Part1 (5.5)
SET time_zone='+03:00';
CREATE TABLE t1 (a DATETIME NOT NULL);
INSERT INTO t1 VALUES ('2009-09-20 07:32:39.06');
INSERT INTO t1 VALUES ('0000-00-00 00:00:00.00');
CREATE VIEW v1 AS SELECT * FROM t1;
SELECT CAST(UNIX_TIMESTAMP(a) AS DECIMAL(25,3)) AS c1 FROM v1 ORDER BY 1;
c1
Sergei Golubchik's avatar
Sergei Golubchik committed
1704
NULL
1705 1706 1707 1708 1709
1253421159.000
DROP VIEW v1;
DROP TABLE t1;
SET time_zone=DEFAULT;
#
1710 1711 1712 1713 1714 1715 1716
# Bug #59686 crash in String::copy() with time data type
#
SELECT min(timestampadd(month, 1>'', from_days('%Z')));
min(timestampadd(month, 1>'', from_days('%Z')))
NULL
Warnings:
Warning	1292	Truncated incorrect INTEGER value: '%Z'
1717
Warning	1292	Truncated incorrect DOUBLE value: ''
Alexander Barkov's avatar
Alexander Barkov committed
1718
Warning	1292	Incorrect datetime value: '0000-00-00'
1719 1720 1721 1722
create table t1(a time);
insert into t1 values ('00:00:00'),('00:01:00');
select 1 from t1 where 1 < some (select cast(a as datetime) from t1);
1
1723 1724
1
1
1725
drop table t1;
Sergei Golubchik's avatar
Sergei Golubchik committed
1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740
select time('10:10:10') > 10;
time('10:10:10') > 10
1
select time('10:10:10') > 1010;
time('10:10:10') > 1010
1
select time('10:10:09') > 101010;
time('10:10:09') > 101010
0
select time('10:10:10') > 101010;
time('10:10:10') > 101010
0
select time('10:10:11') > 101010;
time('10:10:11') > 101010
1
1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776
select time(' 1 02:03:04') + interval 9 microsecond;
time(' 1 02:03:04') + interval 9 microsecond
26:03:04.000009
select time(' 1 02:03:04') - interval 9 microsecond;
time(' 1 02:03:04') - interval 9 microsecond
26:03:03.999991
select time('-1 02:03:04') + interval 9 microsecond;
time('-1 02:03:04') + interval 9 microsecond
-26:03:03.999991
select time('-1 02:03:04') - interval 9 microsecond;
time('-1 02:03:04') - interval 9 microsecond
-26:03:04.000009
select time(' 1 02:03:04') + interval '4:4:4' hour_second;
time(' 1 02:03:04') + interval '4:4:4' hour_second
30:07:08
select time(' 1 02:03:04') - interval '4:4:4' hour_second;
time(' 1 02:03:04') - interval '4:4:4' hour_second
21:59:00
select time('-1 02:03:04') + interval '4:4:4' hour_second;
time('-1 02:03:04') + interval '4:4:4' hour_second
-21:59:00
select time('-1 02:03:04') - interval '4:4:4' hour_second;
time('-1 02:03:04') - interval '4:4:4' hour_second
-30:07:08
select time(' 1 02:03:04') + interval 2 day;
time(' 1 02:03:04') + interval 2 day
74:03:04
select time(' 1 02:03:04') - interval 2 day;
time(' 1 02:03:04') - interval 2 day
-21:56:56
select time('-1 02:03:04') + interval 2 day;
time('-1 02:03:04') + interval 2 day
21:56:56
select time('-1 02:03:04') - interval 2 day;
time('-1 02:03:04') - interval 2 day
-74:03:04
1777 1778 1779 1780 1781 1782 1783 1784 1785 1786
select time('10 02:03:04') + interval 30 day;
time('10 02:03:04') + interval 30 day
NULL
Warnings:
Warning	1441	Datetime function: time field overflow
select time('10 02:03:04') + interval 1 year;
time('10 02:03:04') + interval 1 year
NULL
Warnings:
Warning	1441	Datetime function: time field overflow
1787 1788
select cast('131415.123e0' as time);
cast('131415.123e0' as time)
1789
NULL
1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808
Warnings:
Warning	1292	Truncated incorrect time value: '131415.123e0'
select cast('2010-01-02 03:04:05' as datetime) between null and '2010-01-02 03:04:04';
cast('2010-01-02 03:04:05' as datetime) between null and '2010-01-02 03:04:04'
0
select least(time('1:2:3'), '01:02:04', null) div 1;
least(time('1:2:3'), '01:02:04', null) div 1
NULL
select truncate(least(time('1:2:3'), '01:02:04', null), 6);
truncate(least(time('1:2:3'), '01:02:04', null), 6)
NULL
select cast(least(time('1:2:3'), '01:02:04', null) as decimal(3,1));
cast(least(time('1:2:3'), '01:02:04', null) as decimal(3,1))
NULL
select unix_timestamp(null);
unix_timestamp(null)
NULL
select truncate(date('2010-40-10'), 6);
truncate(date('2010-40-10'), 6)
1809
NULL
1810 1811 1812 1813
Warnings:
Warning	1292	Incorrect datetime value: '2010-40-10'
select extract(month from '2010-40-50');
extract(month from '2010-40-50')
1814
NULL
1815 1816 1817 1818 1819
Warnings:
Warning	1292	Incorrect datetime value: '2010-40-50'
select subtime('0000-00-10 10:10:10', '30 10:00:00');
subtime('0000-00-10 10:10:10', '30 10:00:00')
NULL
1820 1821 1822
select cast(str_to_date(NULL, '%H:%i:%s') as time);
cast(str_to_date(NULL, '%H:%i:%s') as time)
NULL
Sergei Golubchik's avatar
Sergei Golubchik committed
1823 1824 1825 1826
create table t1 (f1 datetime, key (f1));
insert into t1 values ('2000-09-12 00:00:00'), ('2007-04-25 05:08:49');
select * from t1 where f1 > time('-23:00:06');
f1
1827
drop table t1;
1828 1829 1830
select maketime(20,61,10)+0;
maketime(20,61,10)+0
NULL
1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856
create table t1 (f2 int not null) ;
insert into t1 values (0),(0);
select last_day(f2) from t1;
last_day(f2)
NULL
NULL
Warnings:
Warning	1292	Incorrect datetime value: '0'
Warning	1292	Incorrect datetime value: '0'
select last_day(f2) from t1 where last_day(f2) is null;
last_day(f2)
NULL
NULL
Warnings:
Warning	1292	Incorrect datetime value: '0'
Warning	1292	Incorrect datetime value: '0'
Warning	1292	Incorrect datetime value: '0'
Warning	1292	Incorrect datetime value: '0'
select * from t1 order by last_day (f2);
f2
0
0
Warnings:
Warning	1292	Incorrect datetime value: '0'
Warning	1292	Incorrect datetime value: '0'
drop table t1;
1857
SET timestamp=unix_timestamp('2001-02-03 10:20:30');
1858 1859 1860
select convert_tz(timediff('0000-00-00 00:00:00', cast('2008-03-26 07:09:06' as datetime)), 'UTC', 'Europe/Moscow');
convert_tz(timediff('0000-00-00 00:00:00', cast('2008-03-26 07:09:06' as datetime)), 'UTC', 'Europe/Moscow')
NULL
1861
SET timestamp=DEFAULT;
1862
create table t1 (f1 integer, f2 date);
Sergei Golubchik's avatar
Sergei Golubchik committed
1863
insert into t1 values (1,'2011-05-05'),(2,'2011-05-05'),(3,'2011-05-05'),(4,'2011-05-05'),(5,'2011-05-05'),(6, '2011-05-06');
1864
select * from t1 where 1 and concat(f2)=MAKEDATE(2011, 125);
1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877
f1	f2
1	2011-05-05
2	2011-05-05
3	2011-05-05
4	2011-05-05
5	2011-05-05
drop table t1;
create table t1 (f1 timestamp);
insert into t1 values ('0000-00-00 00:00:00');
select least(1, f1) from t1;
least(1, f1)
0000-00-00 00:00:00
Warnings:
Sergei Golubchik's avatar
Sergei Golubchik committed
1878
Warning	1292	Incorrect datetime value: '1'
1879
drop table t1;
1880 1881 1882 1883 1884
SET timestamp=UNIX_TIMESTAMP('2014-04-14 10:10:10');
select now() > coalesce(time('21:43:24'), date('2010-05-03'));
now() > coalesce(time('21:43:24'), date('2010-05-03'))
0
SET timestamp=UNIX_TIMESTAMP('2014-04-14 22:22:22');
1885 1886 1887
select now() > coalesce(time('21:43:24'), date('2010-05-03'));
now() > coalesce(time('21:43:24'), date('2010-05-03'))
1
1888
SET timestamp=DEFAULT;
1889 1890 1891 1892
create table t1 (f1 timestamp);
select * from t1 where f1 > f1 and f1 <=> timestampadd(hour, 9 , '2010-01-01 16:55:35');
f1
drop table t1;
1893 1894 1895 1896 1897
create table t1 (f1 date);
insert into t1 values ('0000-00-00');
select timestampadd(week, 1, f1) from t1;
timestampadd(week, 1, f1)
NULL
1898 1899
Warnings:
Warning	1292	Incorrect datetime value: '0000-00-00'
1900 1901 1902 1903 1904 1905
select timestampadd(week, 1, date("0000-00-00"));
timestampadd(week, 1, date("0000-00-00"))
NULL
Warnings:
Warning	1292	Incorrect datetime value: '0000-00-00'
drop table t1;
1906 1907 1908 1909 1910
create table t1 (f2 time not null, f3 datetime, f4 int not null, f5 timestamp);
insert ignore t1 values ('04:38:11','0000-00-00 00:00:00',0,'0000-00-00 00:00:00');
select least(greatest(f3, f2, f4), f5) from t1;
least(greatest(f3, f2, f4), f5)
0000-00-00 00:00:00
1911 1912
Warnings:
Warning	1292	Incorrect datetime value: '0'
1913
drop table t1;
1914 1915 1916
select day(coalesce(null));
day(coalesce(null))
NULL
1917 1918 1919
select timestamp(greatest('2002-08-20', '0000-00-00 00:00:00'));
timestamp(greatest('2002-08-20', '0000-00-00 00:00:00'))
2002-08-20 00:00:00
1920 1921 1922 1923 1924 1925
create table t1 (f1 datetime);
insert into t1 values ('0000-00-00 00:00:00');
select cast(f1 AS time) from t1;
cast(f1 AS time)
00:00:00
drop table t1;
1926
SET timestamp=UNIX_TIMESTAMP('2014-06-01 10:20:30');
Sergei Golubchik's avatar
Sergei Golubchik committed
1927 1928
select greatest(cast("0-0-0" as date), cast("10:20:05" as time));
greatest(cast("0-0-0" as date), cast("10:20:05" as time))
1929
2014-06-01
Sergei Golubchik's avatar
Sergei Golubchik committed
1930 1931
select greatest(cast("0-0-0" as date), cast("10:20:05" as time)) = '0000-00-00';
greatest(cast("0-0-0" as date), cast("10:20:05" as time)) = '0000-00-00'
1932 1933 1934
0
select greatest(cast("0-0-0" as date), cast("10:20:05" as time)) = '2014-06-01';
greatest(cast("0-0-0" as date), cast("10:20:05" as time)) = '2014-06-01'
Sergei Golubchik's avatar
Sergei Golubchik committed
1935 1936 1937
1
select cast(greatest(cast("0-0-0" as date), cast("10:20:05" as time)) as datetime(6));
cast(greatest(cast("0-0-0" as date), cast("10:20:05" as time)) as datetime(6))
1938 1939
2014-06-01 00:00:00.000000
SET timestamp=DEFAULT;
Sergei Golubchik's avatar
Sergei Golubchik committed
1940 1941 1942
select microsecond('12:00:00.123456'), microsecond('2009-12-31 23:59:59.000010');
microsecond('12:00:00.123456')	microsecond('2009-12-31 23:59:59.000010')
123456	10
1943 1944
select now(258);
ERROR 42000: Too big precision 258 specified for 'now'. Maximum is 6.
1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956
SELECT 1 FROM DUAL WHERE YEAR(TIMEDIFF(NULL, '12:12:12'));
1
SELECT 1 FROM DUAL WHERE MONTH(TIMEDIFF(NULL, '12:12:12'));
1
SELECT 1 FROM DUAL WHERE DAYOFMONTH(TIMEDIFF(NULL, '12:12:12'));
1
SELECT 1 FROM DUAL WHERE HOUR(TIMEDIFF(NULL, '12:12:12'));
1
SELECT 1 FROM DUAL WHERE MINUTE(TIMEDIFF(NULL, '12:12:12'));
1
SELECT 1 FROM DUAL WHERE SECOND(TIMEDIFF(NULL, '12:12:12'));
1
1957
#
1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024
# MDEV-4511 Assertion `scale <= precision' fails on GROUP BY TIMEDIFF with incorrect types
#
CREATE TABLE t1 (a DATE) ENGINE=MyISAM;
INSERT INTO t1 VALUES ('2005-05-04'),('2000-02-23');
SELECT a FROM t1 GROUP BY TIMEDIFF('2004-06-12',a) * 1;
a
2005-05-04
Warnings:
Warning	1292	Truncated incorrect time value: '2004-06-12'
Warning	1292	Truncated incorrect time value: '2004-06-12'
DROP TABLE t1;
CREATE TABLE t1 (a DATE) ENGINE=MyISAM;
INSERT INTO t1 VALUES ('2005-05-04'),('2000-02-23');
SELECT a FROM t1 GROUP BY ADDTIME(a,'10')*1;
a
2000-02-23
2005-05-04
DROP TABLE t1;
CREATE TABLE t1 (a DATE) ENGINE=MyISAM;
INSERT INTO t1 VALUES ('2005-05-04'),('2000-02-23');
SELECT * FROM t1 GROUP BY SEC_TO_TIME(concat(a,'10'))*1;
a
2000-02-23
2005-05-04
DROP TABLE t1;
CREATE TABLE t1 (a DATE) ENGINE=MyISAM;
INSERT INTO t1 VALUES ('2005-05-04'),('2000-02-23');
SELECT * FROM t1 GROUP BY ADDTIME(timestamp('2001-01-01 00:00:00'),CAST(a AS SIGNED)&0xF)*1;
a
2005-05-04
2000-02-23
DROP TABLE t1;
CREATE TABLE t1 (a DATE) ENGINE=MyISAM;
INSERT INTO t1 VALUES ('2005-05-04'),('2000-02-23');
SELECT * FROM t1 GROUP BY STR_TO_DATE(a,concat('%Y-%m-%d.%f',if(rand(),'','')))*1;
a
2000-02-23
2005-05-04
DROP TABLE t1;
CREATE TABLE t1 AS SELECT
STR_TO_DATE('2001-01-01', '%Y-%m-%d') AS date_only,
STR_TO_DATE('10:10:10', '%H:%i:%s') AS time_only,
STR_TO_DATE('10:10:10.123', '%H:%i:%s.%f') AS time_microsecond,
STR_TO_DATE('2001-01-01 10:10:10', '%Y-%m-%d %H:%i:%s') AS date_time,
STR_TO_DATE('2001-01-01 10:10:10.123', '%Y-%m-%d %H:%i:%s.%f') AS date_time_microsecond;
SHOW COLUMNS FROM t1;
Field	Type	Null	Key	Default	Extra
date_only	date	YES		NULL	
time_only	time	YES		NULL	
time_microsecond	time(6)	YES		NULL	
date_time	datetime	YES		NULL	
date_time_microsecond	datetime(6)	YES		NULL	
DROP TABLE t1;
CREATE TABLE t1 AS SELECT
SEC_TO_TIME(1)+0.1,
SEC_TO_TIME(1.1)+0.1,
SEC_TO_TIME(1.12)+0.1,
SEC_TO_TIME(1.123456)+0.1,
SEC_TO_TIME(1.1234567)+0.1;
SHOW COLUMNS FROM t1;
Field	Type	Null	Key	Default	Extra
SEC_TO_TIME(1)+0.1	decimal(12,1)	YES		NULL	
SEC_TO_TIME(1.1)+0.1	decimal(13,1)	YES		NULL	
SEC_TO_TIME(1.12)+0.1	decimal(14,2)	YES		NULL	
SEC_TO_TIME(1.123456)+0.1	decimal(18,6)	YES		NULL	
SEC_TO_TIME(1.1234567)+0.1	decimal(18,6)	YES		NULL	
DROP TABLE t1;
2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047
CREATE TABLE t1 (a DATE) ENGINE=MyISAM;
INSERT INTO t1 VALUES ('2005-05-04'),('2000-02-23');
SELECT * FROM t1 GROUP BY FROM_UNIXTIME(concat(a,'10'))*1;
a
2000-02-23
2005-05-04
SELECT * FROM t1 GROUP BY (-FROM_UNIXTIME(concat(a,'10')))*1;
a
2005-05-04
2000-02-23
SELECT * FROM t1 GROUP BY (-FROM_UNIXTIME(concat(a,'10')));
a
2005-05-04
2000-02-23
SELECT * FROM t1 GROUP BY ABS(FROM_UNIXTIME(concat(a,'10')));
a
2000-02-23
2005-05-04
SELECT * FROM t1 GROUP BY @a:=(FROM_UNIXTIME(concat(a,'10'))*1);
a
2000-02-23
2005-05-04
DROP TABLE t1;
2048
SET TIME_ZONE='+02:00';
2049 2050 2051 2052 2053 2054 2055
#
# MDEV-6302 Wrong result set when using GROUP BY FROM_UNIXTIME(...)+0
#
CREATE TABLE t1 (a DATE);
INSERT INTO t1 VALUES ('2005-05-04'),('2000-02-23');
SELECT a, FROM_UNIXTIME(CONCAT(a,'10')) AS f1, FROM_UNIXTIME(CONCAT(a,'10'))+0 AS f2 FROM t1;
a	f1	f2
2056 2057
2005-05-04	1970-01-01 02:33:25	19700101023325.000000
2000-02-23	1970-01-01 02:33:20	19700101023320.000000
2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081
SELECT * FROM t1 GROUP BY FROM_UNIXTIME(CONCAT(a,'10'))+0;
a
2000-02-23
2005-05-04
DROP TABLE t1;
CREATE TABLE t1 (a DATE) ENGINE=MyISAM;
INSERT INTO t1 VALUES ('2005-05-04'),('2000-02-23');
SELECT * FROM t1 GROUP BY FROM_UNIXTIME(concat(a,'10'))/1;
a
2000-02-23
2005-05-04
DROP TABLE t1;
CREATE TABLE t1 (a DATE);
INSERT INTO t1 VALUES ('2005-05-04');
SELECT CONCAT(FROM_UNIXTIME(CONCAT(a,'10')) MOD FROM_UNIXTIME(CONCAT(a,'10'))) AS f2 FROM t1;
f2
0.000000
SELECT CHAR_LENGTH(CONCAT(FROM_UNIXTIME(CONCAT(a,'10')) MOD FROM_UNIXTIME(CONCAT(a,'10')))) AS f2 FROM t1;
f2
8
CREATE TABLE t2 AS SELECT CONCAT(FROM_UNIXTIME(CONCAT(a,'10')) MOD FROM_UNIXTIME(CONCAT(a,'10'))) AS f2 FROM t1;
SHOW CREATE TABLE t2;
Table	Create Table
t2	CREATE TABLE `t2` (
Sergei Golubchik's avatar
Sergei Golubchik committed
2082
  `f2` varchar(26) DEFAULT NULL
2083 2084 2085 2086 2087
) ENGINE=MyISAM DEFAULT CHARSET=latin1
SELECT * FROM t2;
f2
0.000000
DROP TABLE t1,t2;
2088
#
2089 2090 2091 2092 2093 2094
# MDEV-4635 Crash in UNIX_TIMESTAMP(STR_TO_DATE('2020','%Y'))
#
SELECT UNIX_TIMESTAMP(STR_TO_DATE('2020','%Y'));
UNIX_TIMESTAMP(STR_TO_DATE('2020','%Y'))
NULL
Warnings:
2095
Warning	1411	Incorrect datetime value: '2020' for function str_to_date
2096
SET TIME_ZONE=DEFAULT;
2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120
#
#  MDEV-4863 COALESCE(time_or_datetime) returns wrong results in numeric context
#
CREATE TABLE t1 (a TIMESTAMP(3));
INSERT INTO t1 VALUES ('2001-01-01 10:20:30.999');
SELECT CAST(COALESCE(a,a) AS SIGNED) AS c1, CAST(COALESCE(a,a) AS DECIMAL(25,3)) AS c2, ROUND(COALESCE(a,a)) AS c2  FROM t1;
c1	c2	c2
20010101102030	20010101102030.999	20010101102031
DROP TABLE t1;
CREATE TABLE t1 (a TIME(3));
INSERT INTO t1 VALUES ('10:20:30.999');
SELECT CAST(COALESCE(a,a) AS SIGNED) AS c1, CAST(COALESCE(a,a) AS DECIMAL(25,3)) AS c2, ROUND(COALESCE(a,a)) AS c2  FROM t1;
c1	c2	c2
102030	102030.999	102031
DROP TABLE t1;
SELECT
CAST(COALESCE(DATE('2001-01-01'),TIMESTAMP('2001-01-02 10:20:30')) AS SIGNED) AS c1,
CAST(COALESCE(DATE('2001-01-01'),TIMESTAMP('2001-01-02 10:20:30')) AS DECIMAL(25,4)) AS c2,
COALESCE(DATE('2001-01-01'),TIMESTAMP('2001-01-02 10:20:30'))+0e0 AS c3,
CONCAT(COALESCE(DATE('2001-01-01'),TIMESTAMP('2001-01-02 10:20:30'))) AS c4,
TIME(COALESCE(DATE('2001-01-01'),TIMESTAMP('2001-01-02 10:20:30'))) AS c5,
DATE(COALESCE(DATE('2001-01-01'),TIMESTAMP('2001-01-02 10:20:30'))) AS c6,
TIMESTAMP(COALESCE(DATE('2001-01-01'),TIMESTAMP('2001-01-02 10:20:30'))) AS c7;
c1	c2	c3	c4	c5	c6	c7
2121
20010101000000	20010101000000.0000	20010101000000	2001-01-01 00:00:00	00:00:00	2001-01-01	2001-01-01 00:00:00
2122 2123 2124 2125 2126 2127 2128 2129 2130
SELECT
CAST(COALESCE(TIMESTAMP('2001-01-02 10:20:30'),DATE('2001-01-01')) AS SIGNED) AS c1,
CAST(COALESCE(TIMESTAMP('2001-01-02 10:20:30'),DATE('2001-01-01')) AS DECIMAL(25,4)) AS c2,
COALESCE(TIMESTAMP('2001-01-02 10:20:30'),DATE('2001-01-01'))+0e0 AS c3,
CONCAT(COALESCE(TIMESTAMP('2001-01-02 10:20:30'),DATE('2001-01-01'))) AS c4,
TIME(COALESCE(TIMESTAMP('2001-01-02 10:20:30'),DATE('2001-01-01'))) AS c5,
DATE(COALESCE(TIMESTAMP('2001-01-02 10:20:30'),DATE('2001-01-01'))) AS c6,
TIMESTAMP(COALESCE(TIMESTAMP('2001-01-02 10:20:30'),DATE('2001-01-01'))) AS c7;
c1	c2	c3	c4	c5	c6	c7
2131
20010102102030	20010102102030.0000	20010102102030	2001-01-02 10:20:30	10:20:30	2001-01-02	2001-01-02 10:20:30
2132 2133 2134 2135 2136 2137 2138 2139 2140
SELECT
CAST(IFNULL(DATE('2001-01-01'),TIMESTAMP('2001-01-02 10:20:30')) AS SIGNED) AS c1,
CAST(IFNULL(DATE('2001-01-01'),TIMESTAMP('2001-01-02 10:20:30')) AS DECIMAL(25,4)) AS c2,
IFNULL(DATE('2001-01-01'),TIMESTAMP('2001-01-02 10:20:30'))+0e0 AS c3,
CONCAT(IFNULL(DATE('2001-01-01'),TIMESTAMP('2001-01-02 10:20:30'))) AS c4,
TIME(IFNULL(DATE('2001-01-01'),TIMESTAMP('2001-01-02 10:20:30'))) AS c5,
DATE(IFNULL(DATE('2001-01-01'),TIMESTAMP('2001-01-02 10:20:30'))) AS c6,
TIMESTAMP(IFNULL(DATE('2001-01-01'),TIMESTAMP('2001-01-02 10:20:30'))) AS c7;
c1	c2	c3	c4	c5	c6	c7
2141
20010101000000	20010101000000.0000	20010101000000	2001-01-01 00:00:00	00:00:00	2001-01-01	2001-01-01 00:00:00
2142 2143 2144 2145 2146 2147 2148 2149 2150
SELECT
CAST(IFNULL(TIMESTAMP('2001-01-02 10:20:30'),DATE('2001-01-01')) AS SIGNED) AS c1,
CAST(IFNULL(TIMESTAMP('2001-01-02 10:20:30'),DATE('2001-01-01')) AS DECIMAL(25,4)) AS c2,
IFNULL(TIMESTAMP('2001-01-02 10:20:30'),DATE('2001-01-01'))+0e0 AS c3,
CONCAT(IFNULL(TIMESTAMP('2001-01-02 10:20:30'),DATE('2001-01-01'))) AS c4,
TIME(IFNULL(TIMESTAMP('2001-01-02 10:20:30'),DATE('2001-01-01'))) AS c5,
DATE(IFNULL(TIMESTAMP('2001-01-02 10:20:30'),DATE('2001-01-01'))) AS c6,
TIMESTAMP(IFNULL(TIMESTAMP('2001-01-02 10:20:30'),DATE('2001-01-01'))) AS c7;
c1	c2	c3	c4	c5	c6	c7
2151
20010102102030	20010102102030.0000	20010102102030	2001-01-02 10:20:30	10:20:30	2001-01-02	2001-01-02 10:20:30
2152 2153 2154 2155 2156 2157 2158 2159 2160
SELECT
CAST(IF(1,DATE('2001-01-01'),TIMESTAMP('2001-01-02 10:20:30')) AS SIGNED) AS c1,
CAST(IF(1,DATE('2001-01-01'),TIMESTAMP('2001-01-02 10:20:30')) AS DECIMAL(25,4)) AS c2,
IF(1,DATE('2001-01-01'),TIMESTAMP('2001-01-02 10:20:30'))+0e0 AS c3,
CONCAT(IF(1,DATE('2001-01-01'),TIMESTAMP('2001-01-02 10:20:30'))) AS c4,
TIME(IF(1,DATE('2001-01-01'),TIMESTAMP('2001-01-02 10:20:30'))) AS c5,
DATE(IF(1,DATE('2001-01-01'),TIMESTAMP('2001-01-02 10:20:30'))) AS c6,
TIMESTAMP(IF(1,DATE('2001-01-01'),TIMESTAMP('2001-01-02 10:20:30'))) AS c7;
c1	c2	c3	c4	c5	c6	c7
2161
20010101000000	20010101000000.0000	20010101000000	2001-01-01 00:00:00	00:00:00	2001-01-01	2001-01-01 00:00:00
2162 2163 2164 2165 2166 2167 2168 2169 2170
SELECT
CAST(IF(0,DATE('2001-01-01'),TIMESTAMP('2001-01-02 10:20:30')) AS SIGNED) AS c1,
CAST(IF(0,DATE('2001-01-01'),TIMESTAMP('2001-01-02 10:20:30')) AS DECIMAL(25,4)) AS c2,
IF(0,DATE('2001-01-01'),TIMESTAMP('2001-01-02 10:20:30'))+0e0 AS c3,
CONCAT(IF(0,DATE('2001-01-01'),TIMESTAMP('2001-01-02 10:20:30'))) AS c4,
TIME(IF(0,DATE('2001-01-01'),TIMESTAMP('2001-01-02 10:20:30'))) AS c5,
DATE(IF(0,DATE('2001-01-01'),TIMESTAMP('2001-01-02 10:20:30'))) AS c6,
TIMESTAMP(IF(0,DATE('2001-01-01'),TIMESTAMP('2001-01-02 10:20:30'))) AS c7;
c1	c2	c3	c4	c5	c6	c7
2171
20010102102030	20010102102030.0000	20010102102030	2001-01-02 10:20:30	10:20:30	2001-01-02	2001-01-02 10:20:30
2172 2173 2174 2175 2176 2177 2178 2179 2180
SELECT
CAST(CASE WHEN 1 THEN DATE('2001-01-01') ELSE TIMESTAMP('2001-01-02 10:20:30') END AS SIGNED) AS c1,
CAST(CASE WHEN 1 THEN DATE('2001-01-01') ELSE TIMESTAMP('2001-01-02 10:20:30') END AS DECIMAL(25,4)) AS c2,
CASE WHEN 1 THEN DATE('2001-01-01') ELSE TIMESTAMP('2001-01-02 10:20:30') END+0e0 AS c3,
CONCAT(CASE WHEN 1 THEN DATE('2001-01-01') ELSE TIMESTAMP('2001-01-02 10:20:30') END) AS c4,
TIME(CASE WHEN 1 THEN DATE('2001-01-01') ELSE TIMESTAMP('2001-01-02 10:20:30') END) AS c5,
DATE(CASE WHEN 1 THEN DATE('2001-01-01') ELSE TIMESTAMP('2001-01-02 10:20:30') END) AS c6,
TIMESTAMP(CASE WHEN 1 THEN DATE('2001-01-01') ELSE TIMESTAMP('2001-01-02 10:20:30') END) AS c7;
c1	c2	c3	c4	c5	c6	c7
2181
20010101000000	20010101000000.0000	20010101000000	2001-01-01 00:00:00	00:00:00	2001-01-01	2001-01-01 00:00:00
2182 2183 2184 2185 2186 2187 2188 2189 2190
SELECT
CAST(CASE WHEN 0 THEN DATE('2001-01-01') ELSE TIMESTAMP('2001-01-02 10:20:30') END AS SIGNED) AS c1,
CAST(CASE WHEN 0 THEN DATE('2001-01-01') ELSE TIMESTAMP('2001-01-02 10:20:30') END AS DECIMAL(25,4)) AS c2,
CASE WHEN 0 THEN DATE('2001-01-01') ELSE TIMESTAMP('2001-01-02 10:20:30') END+0e0 AS c3,
CONCAT(CASE WHEN 0 THEN DATE('2001-01-01') ELSE TIMESTAMP('2001-01-02 10:20:30') END) AS c4,
TIME(CASE WHEN 0 THEN DATE('2001-01-01') ELSE TIMESTAMP('2001-01-02 10:20:30') END) AS c5,
DATE(CASE WHEN 0 THEN DATE('2001-01-01') ELSE TIMESTAMP('2001-01-02 10:20:30') END) AS c6,
TIMESTAMP(CASE WHEN 0 THEN DATE('2001-01-01') ELSE TIMESTAMP('2001-01-02 10:20:30') END) AS c7;
c1	c2	c3	c4	c5	c6	c7
2191
20010102102030	20010102102030.0000	20010102102030	2001-01-02 10:20:30	10:20:30	2001-01-02	2001-01-02 10:20:30
2192 2193 2194 2195 2196 2197 2198 2199
CREATE TABLE t1 AS SELECT
CONCAT(COALESCE(TIME(101010),TIME(101010))) AS c1,
CONCAT(IF(0,TIME(101010),TIME(101010))) AS c2,
CONCAT(IFNULL(TIME(101010),TIME(101010))) AS c3,
CONCAT(CASE WHEN 1 THEN TIME(101010) ELSE TIME(101010) END) AS c4;
SHOW CREATE TABLE t1;
Table	Create Table
t1	CREATE TABLE `t1` (
Alexander Barkov's avatar
Alexander Barkov committed
2200 2201 2202 2203
  `c1` varchar(10) DEFAULT NULL,
  `c2` varchar(10) DEFAULT NULL,
  `c3` varchar(10) DEFAULT NULL,
  `c4` varchar(10) DEFAULT NULL
2204 2205
) ENGINE=MyISAM DEFAULT CHARSET=latin1
DROP TABLE t1;
2206
#
2207 2208
# MDEV-4870 Wrong values of CASE, COALESCE, IFNULL on a combination of different temporal types
#
2209
SET timestamp=UNIX_TIMESTAMP('2001-01-01 10:20:30');
2210 2211 2212 2213
CREATE TABLE t1 (dt2 DATETIME(2), t3 TIME(3), d DATE);
INSERT INTO t1 VALUES ('2001-01-01 00:00:00.12', '00:00:00.567', '2002-01-01');
SELECT CASE WHEN 0 THEN dt2 ELSE t3 END FROM t1;
CASE WHEN 0 THEN dt2 ELSE t3 END
2214
2001-01-01 00:00:00.567
2215 2216 2217
CREATE TABLE t2 AS SELECT CASE WHEN 0 THEN dt2 ELSE t3 END FROM t1;
SELECT * FROM t2;
CASE WHEN 0 THEN dt2 ELSE t3 END
2218
2001-01-01 00:00:00.567
2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236
SHOW COLUMNS FROM t2;
Field	Type	Null	Key	Default	Extra
CASE WHEN 0 THEN dt2 ELSE t3 END	datetime(3)	YES		NULL	
DROP TABLE t2;
SELECT CASE WHEN 1 THEN dt2 ELSE t3 END FROM t1;
CASE WHEN 1 THEN dt2 ELSE t3 END
2001-01-01 00:00:00.120
SELECT CONCAT(CASE WHEN 1 THEN dt2 ELSE t3 END) FROM t1;
CONCAT(CASE WHEN 1 THEN dt2 ELSE t3 END)
2001-01-01 00:00:00.120
SELECT CONCAT(CASE WHEN 0 THEN t3 ELSE dt2 END) FROM t1;
CONCAT(CASE WHEN 0 THEN t3 ELSE dt2 END)
2001-01-01 00:00:00.120
SELECT CONCAT(CASE WHEN 1 THEN d ELSE t3 END) FROM t1;
CONCAT(CASE WHEN 1 THEN d ELSE t3 END)
2002-01-01 00:00:00.000
SELECT CASE WHEN 1 THEN t3 ELSE d END FROM t1;
CASE WHEN 1 THEN t3 ELSE d END
2237
2001-01-01 00:00:00.567
2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256
SELECT COALESCE(d, t3) FROM t1;
COALESCE(d, t3)
2002-01-01 00:00:00.000
SELECT CONCAT(COALESCE(d, t3)) FROM t1;
CONCAT(COALESCE(d, t3))
2002-01-01 00:00:00.000
SELECT COALESCE(dt2, t3) FROM t1;
COALESCE(dt2, t3)
2001-01-01 00:00:00.120
SELECT CONCAT(COALESCE(dt2, t3)) FROM t1;
CONCAT(COALESCE(dt2, t3))
2001-01-01 00:00:00.120
SELECT IFNULL(dt2, t3), CONCAT(IFNULL(dt2, t3)) FROM t1;
IFNULL(dt2, t3)	CONCAT(IFNULL(dt2, t3))
2001-01-01 00:00:00.120	2001-01-01 00:00:00.120
SELECT IFNULL(d, t3), CONCAT(IFNULL(d, t3)) FROM t1;
IFNULL(d, t3)	CONCAT(IFNULL(d, t3))
2002-01-01 00:00:00.000	2002-01-01 00:00:00.000
DROP TABLE t1;
2257
SET timestamp=DEFAULT;
2258
#
2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402
# MDEV-4724 Some temporal functions do not preserve microseconds
#
SELECT MAKETIME(10,10,10.231);
MAKETIME(10,10,10.231)
10:10:10.231
SELECT MAKETIME(0, 0, 59.9);
MAKETIME(0, 0, 59.9)
00:00:59.9
CREATE TABLE t1 AS SELECT
MAKETIME(10,00,00),
MAKETIME(10,00,00.1),
MAKETIME(10,00,00.12),
MAKETIME(10,00,00.123),
MAKETIME(10,00,00.1234),
MAKETIME(10,00,00.12345),
MAKETIME(10,00,00.123456);
SHOW COLUMNS FROM t1;
Field	Type	Null	Key	Default	Extra
MAKETIME(10,00,00)	time	YES		NULL	
MAKETIME(10,00,00.1)	time(1)	YES		NULL	
MAKETIME(10,00,00.12)	time(2)	YES		NULL	
MAKETIME(10,00,00.123)	time(3)	YES		NULL	
MAKETIME(10,00,00.1234)	time(4)	YES		NULL	
MAKETIME(10,00,00.12345)	time(5)	YES		NULL	
MAKETIME(10,00,00.123456)	time(6)	YES		NULL	
DROP TABLE t1;
CREATE TABLE t1 AS SELECT
TIME('10:00:00'),
TIME('10:00:00.1'),
TIME('10:00:00.12'),
TIME('10:00:00.123'),
TIME('10:00:00.1234'),
TIME('10:00:00.12345'),
TIME('10:00:00.12346');
SHOW COLUMNS FROM t1;
Field	Type	Null	Key	Default	Extra
TIME('10:00:00')	time	YES		NULL	
TIME('10:00:00.1')	time(1)	YES		NULL	
TIME('10:00:00.12')	time(2)	YES		NULL	
TIME('10:00:00.123')	time(3)	YES		NULL	
TIME('10:00:00.1234')	time(4)	YES		NULL	
TIME('10:00:00.12345')	time(5)	YES		NULL	
TIME('10:00:00.12346')	time(5)	YES		NULL	
DROP TABLE t1;
SET TIME_ZONE='+00:00';
SET TIMESTAMP=UNIX_TIMESTAMP('2012-10-16 22:46:17');
SELECT NOW(), UNIX_TIMESTAMP(), UNIX_TIMESTAMP(NOW()),UNIX_TIMESTAMP('2012-10-16 22:46:17');
NOW()	UNIX_TIMESTAMP()	UNIX_TIMESTAMP(NOW())	UNIX_TIMESTAMP('2012-10-16 22:46:17')
2012-10-16 22:46:17	1350427577	1350427577	1350427577
SET TIMESTAMP=UNIX_TIMESTAMP('1970-01-02 03:04:05.123456');
SELECT @@timestamp, FROM_UNIXTIME(@@timestamp);
@@timestamp	FROM_UNIXTIME(@@timestamp)
97445.123456	1970-01-02 03:04:05.123456
SET TIME_ZONE=DEFAULT;
SET TIMESTAMP=DEFAULT;
SELECT TIME('2012-10-16 15:54:16.12');
TIME('2012-10-16 15:54:16.12')
15:54:16.12
SELECT TIMESTAMP('2012-10-16 15:54:16.12');
TIMESTAMP('2012-10-16 15:54:16.12')
2012-10-16 15:54:16.12
SELECT TIMEDIFF('10:10:10.1','00:00:00');
TIMEDIFF('10:10:10.1','00:00:00')
10:10:10.1
SELECT TIME_TO_SEC('10:10:10');
TIME_TO_SEC('10:10:10')
36610
SELECT ADDTIME(TIME('10:10:10.1'),'10:10:10.12');
ADDTIME(TIME('10:10:10.1'),'10:10:10.12')
20:20:20.22
SELECT ADDTIME(TIMESTAMP('2001-01-01 10:10:10.1'),'10:10:10.12');
ADDTIME(TIMESTAMP('2001-01-01 10:10:10.1'),'10:10:10.12')
2001-01-01 20:20:20.22
SELECT DATE_ADD('2001-01-01 00:00:00', INTERVAL 1 SECOND);
DATE_ADD('2001-01-01 00:00:00', INTERVAL 1 SECOND)
2001-01-01 00:00:01
SELECT DATE_ADD('2001-01-01 00:00:00.1', INTERVAL 1 SECOND);
DATE_ADD('2001-01-01 00:00:00.1', INTERVAL 1 SECOND)
2001-01-01 00:00:01.1
SELECT DATE_ADD('2001-01-01 00:00:00.12', INTERVAL 1 SECOND);
DATE_ADD('2001-01-01 00:00:00.12', INTERVAL 1 SECOND)
2001-01-01 00:00:01.12
SELECT DATE_ADD('2001-01-01 00:00:00.123', INTERVAL 1 SECOND);
DATE_ADD('2001-01-01 00:00:00.123', INTERVAL 1 SECOND)
2001-01-01 00:00:01.123
SELECT DATE_ADD('2001-01-01 00:00:00.1234', INTERVAL 1 SECOND);
DATE_ADD('2001-01-01 00:00:00.1234', INTERVAL 1 SECOND)
2001-01-01 00:00:01.1234
SELECT DATE_ADD('2001-01-01 00:00:00.12345', INTERVAL 1 SECOND);
DATE_ADD('2001-01-01 00:00:00.12345', INTERVAL 1 SECOND)
2001-01-01 00:00:01.12345
SELECT DATE_ADD('2001-01-01 00:00:00.123456', INTERVAL 1 SECOND);
DATE_ADD('2001-01-01 00:00:00.123456', INTERVAL 1 SECOND)
2001-01-01 00:00:01.123456
SELECT DATE_ADD('2001-01-01 00:00:00', INTERVAL 1 SECOND);
DATE_ADD('2001-01-01 00:00:00', INTERVAL 1 SECOND)
2001-01-01 00:00:01
SELECT DATE_ADD('2001-01-01 00:00:00', INTERVAL 1.1 SECOND);
DATE_ADD('2001-01-01 00:00:00', INTERVAL 1.1 SECOND)
2001-01-01 00:00:01.1
SELECT DATE_ADD('2001-01-01 00:00:00', INTERVAL 1.12 SECOND);
DATE_ADD('2001-01-01 00:00:00', INTERVAL 1.12 SECOND)
2001-01-01 00:00:01.12
SELECT DATE_ADD('2001-01-01 00:00:00', INTERVAL 1.123 SECOND);
DATE_ADD('2001-01-01 00:00:00', INTERVAL 1.123 SECOND)
2001-01-01 00:00:01.123
SELECT DATE_ADD('2001-01-01 00:00:00', INTERVAL 1.1234 SECOND);
DATE_ADD('2001-01-01 00:00:00', INTERVAL 1.1234 SECOND)
2001-01-01 00:00:01.1234
SELECT DATE_ADD('2001-01-01 00:00:00', INTERVAL 1.12345 SECOND);
DATE_ADD('2001-01-01 00:00:00', INTERVAL 1.12345 SECOND)
2001-01-01 00:00:01.12345
SELECT DATE_ADD('2001-01-01 00:00:00', INTERVAL 1.123456 SECOND);
DATE_ADD('2001-01-01 00:00:00', INTERVAL 1.123456 SECOND)
2001-01-01 00:00:01.123456
SELECT DATE_ADD('2001-01-01 00:00:00', INTERVAL -1 SECOND);
DATE_ADD('2001-01-01 00:00:00', INTERVAL -1 SECOND)
2000-12-31 23:59:59
SELECT DATE_ADD('2001-01-01 00:00:00', INTERVAL -1.1 SECOND);
DATE_ADD('2001-01-01 00:00:00', INTERVAL -1.1 SECOND)
2000-12-31 23:59:58.9
SELECT DATE_ADD('2001-01-01 00:00:00', INTERVAL -1.12 SECOND);
DATE_ADD('2001-01-01 00:00:00', INTERVAL -1.12 SECOND)
2000-12-31 23:59:58.88
SELECT DATE_ADD('2001-01-01 00:00:00', INTERVAL -1.123 SECOND);
DATE_ADD('2001-01-01 00:00:00', INTERVAL -1.123 SECOND)
2000-12-31 23:59:58.877
SELECT DATE_ADD('2001-01-01 00:00:00', INTERVAL -1.1234 SECOND);
DATE_ADD('2001-01-01 00:00:00', INTERVAL -1.1234 SECOND)
2000-12-31 23:59:58.8766
SELECT DATE_ADD('2001-01-01 00:00:00', INTERVAL -1.12345 SECOND);
DATE_ADD('2001-01-01 00:00:00', INTERVAL -1.12345 SECOND)
2000-12-31 23:59:58.87655
SELECT DATE_ADD('2001-01-01 00:00:00', INTERVAL -1.123456 SECOND);
DATE_ADD('2001-01-01 00:00:00', INTERVAL -1.123456 SECOND)
2000-12-31 23:59:58.876544
SELECT DATE_ADD('2001-01-01 00:00:00', INTERVAL 'xxx' SECOND);
DATE_ADD('2001-01-01 00:00:00', INTERVAL 'xxx' SECOND)
2001-01-01 00:00:00.000000
Warnings:
Warning	1292	Truncated incorrect DECIMAL value: 'xxx'
SELECT CONVERT_TZ('2001-01-01 10:20:30.12','+00:00','+01:00');
CONVERT_TZ('2001-01-01 10:20:30.12','+00:00','+01:00')
2001-01-01 11:20:30.12
2403
#
2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426
# MDEV-4861 TIME/DATETIME arithmetics does not preserve INTERVAL precision
#
CREATE TABLE t1 (t0 TIME);
INSERT INTO t1 VALUES ('00:00:00');
SELECT t0 + INTERVAL 1.1 SECOND FROM t1;
t0 + INTERVAL 1.1 SECOND
00:00:01.1
CREATE TABLE t2 AS SELECT t0 + INTERVAL 1.1 SECOND FROM t1;
SHOW COLUMNS FROM t2;
Field	Type	Null	Key	Default	Extra
t0 + INTERVAL 1.1 SECOND	time(1)	YES		NULL	
DROP TABLE t1,t2;
CREATE TABLE t1 (t0 DATETIME);
INSERT INTO t1 VALUES ('2001-01-01 00:00:00');
SELECT t0 + INTERVAL 1.1 SECOND FROM t1;
t0 + INTERVAL 1.1 SECOND
2001-01-01 00:00:01.1
CREATE TABLE t2 AS SELECT t0 + INTERVAL 1.1 SECOND FROM t1;
SHOW COLUMNS FROM t2;
Field	Type	Null	Key	Default	Extra
t0 + INTERVAL 1.1 SECOND	datetime(1)	YES		NULL	
DROP TABLE t1, t2;
#
2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438
# MDEV-4843 Wrong data type for TIMESTAMP('2001-01-01','10:10:10')
#
CREATE TABLE t1 AS SELECT
TIMESTAMP('2001-01-01','10:10:10'),
TIMESTAMP('2001-01-01','10:10:10.1'),
TIMESTAMP('2001-01-01','10:10:10.12'),
TIMESTAMP('2001-01-01','10:10:10.123'),
TIMESTAMP('2001-01-01','10:10:10.1234'),
TIMESTAMP('2001-01-01','10:10:10.12345'),
TIMESTAMP('2001-01-01','10:10:10.123456'),
TIMESTAMP('2001-01-01','10:10:10.1234567');
Warnings:
Sergei Golubchik's avatar
Sergei Golubchik committed
2439
Note	1292	Truncated incorrect time value: '10:10:10.1234567'
2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463
SHOW COLUMNS FROM t1;
Field	Type	Null	Key	Default	Extra
TIMESTAMP('2001-01-01','10:10:10')	datetime	YES		NULL	
TIMESTAMP('2001-01-01','10:10:10.1')	datetime(1)	YES		NULL	
TIMESTAMP('2001-01-01','10:10:10.12')	datetime(2)	YES		NULL	
TIMESTAMP('2001-01-01','10:10:10.123')	datetime(3)	YES		NULL	
TIMESTAMP('2001-01-01','10:10:10.1234')	datetime(4)	YES		NULL	
TIMESTAMP('2001-01-01','10:10:10.12345')	datetime(5)	YES		NULL	
TIMESTAMP('2001-01-01','10:10:10.123456')	datetime(6)	YES		NULL	
TIMESTAMP('2001-01-01','10:10:10.1234567')	datetime(6)	YES		NULL	
SELECT * FROM t1;
TIMESTAMP('2001-01-01','10:10:10')	TIMESTAMP('2001-01-01','10:10:10.1')	TIMESTAMP('2001-01-01','10:10:10.12')	TIMESTAMP('2001-01-01','10:10:10.123')	TIMESTAMP('2001-01-01','10:10:10.1234')	TIMESTAMP('2001-01-01','10:10:10.12345')	TIMESTAMP('2001-01-01','10:10:10.123456')	TIMESTAMP('2001-01-01','10:10:10.1234567')
2001-01-01 10:10:10	2001-01-01 10:10:10.1	2001-01-01 10:10:10.12	2001-01-01 10:10:10.123	2001-01-01 10:10:10.1234	2001-01-01 10:10:10.12345	2001-01-01 10:10:10.123456	2001-01-01 10:10:10.123456
DROP TABLE t1;
CREATE TABLE t1 AS SELECT
TIMESTAMP('2001-01-01 00:00:00','10:10:10'),
TIMESTAMP('2001-01-01 00:00:00.1','10:10:10'),
TIMESTAMP('2001-01-01 00:00:00.12','10:10:10'),
TIMESTAMP('2001-01-01 00:00:00.123','10:10:10'),
TIMESTAMP('2001-01-01 00:00:00.1234','10:10:10'),
TIMESTAMP('2001-01-01 00:00:00.12345','10:10:10'),
TIMESTAMP('2001-01-01 00:00:00.123456','10:10:10'),
TIMESTAMP('2001-01-01 00:00:00.1234567','10:10:10');
Warnings:
Sergei Golubchik's avatar
Sergei Golubchik committed
2464
Note	1292	Truncated incorrect datetime value: '2001-01-01 00:00:00.1234567'
2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478
SHOW COLUMNS FROM t1;
Field	Type	Null	Key	Default	Extra
TIMESTAMP('2001-01-01 00:00:00','10:10:10')	datetime	YES		NULL	
TIMESTAMP('2001-01-01 00:00:00.1','10:10:10')	datetime(1)	YES		NULL	
TIMESTAMP('2001-01-01 00:00:00.12','10:10:10')	datetime(2)	YES		NULL	
TIMESTAMP('2001-01-01 00:00:00.123','10:10:10')	datetime(3)	YES		NULL	
TIMESTAMP('2001-01-01 00:00:00.1234','10:10:10')	datetime(4)	YES		NULL	
TIMESTAMP('2001-01-01 00:00:00.12345','10:10:10')	datetime(5)	YES		NULL	
TIMESTAMP('2001-01-01 00:00:00.123456','10:10:10')	datetime(6)	YES		NULL	
TIMESTAMP('2001-01-01 00:00:00.1234567','10:10:10')	datetime(6)	YES		NULL	
SELECT * FROM t1;
TIMESTAMP('2001-01-01 00:00:00','10:10:10')	TIMESTAMP('2001-01-01 00:00:00.1','10:10:10')	TIMESTAMP('2001-01-01 00:00:00.12','10:10:10')	TIMESTAMP('2001-01-01 00:00:00.123','10:10:10')	TIMESTAMP('2001-01-01 00:00:00.1234','10:10:10')	TIMESTAMP('2001-01-01 00:00:00.12345','10:10:10')	TIMESTAMP('2001-01-01 00:00:00.123456','10:10:10')	TIMESTAMP('2001-01-01 00:00:00.1234567','10:10:10')
2001-01-01 10:10:10	2001-01-01 10:10:10.1	2001-01-01 10:10:10.12	2001-01-01 10:10:10.123	2001-01-01 10:10:10.1234	2001-01-01 10:10:10.12345	2001-01-01 10:10:10.123456	2001-01-01 10:10:10.123456
DROP TABLE t1;
2479
SET timestamp=unix_timestamp('2001-02-03 10:20:30');
2480 2481 2482 2483 2484 2485 2486 2487 2488
CREATE TABLE t1 AS SELECT
TIMESTAMP('00:00:00','10:10:10'),
TIMESTAMP(TIME('00:00:00'),'10:10:10');
SHOW COLUMNS FROM t1;
Field	Type	Null	Key	Default	Extra
TIMESTAMP('00:00:00','10:10:10')	datetime	YES		NULL	
TIMESTAMP(TIME('00:00:00'),'10:10:10')	datetime	YES		NULL	
SELECT * FROM t1;
TIMESTAMP('00:00:00','10:10:10')	TIMESTAMP(TIME('00:00:00'),'10:10:10')
2489
NULL	2001-02-03 10:10:10
2490
DROP TABLE t1;
2491
SET timestamp=DEFAULT;
2492 2493 2494 2495 2496 2497
#
# MDEV-4869 Wrong result of MAKETIME(0, 0, -0.1)
#
SELECT MAKETIME(0, 0, -0.1);
MAKETIME(0, 0, -0.1)
NULL
2498 2499 2500
#
# MDEV-4857 Wrong result of HOUR('1 00:00:00')
#
2501
SET timestamp=unix_timestamp('2001-02-03 10:20:30');
2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512
SELECT HOUR('1 02:00:00'), HOUR('26:00:00');
HOUR('1 02:00:00')	HOUR('26:00:00')
26	26
SELECT HOUR(TIME'1 02:00:00'), HOUR(TIME'26:00:00');
HOUR(TIME'1 02:00:00')	HOUR(TIME'26:00:00')
26	26
SELECT HOUR(TIME('1 02:00:00')), HOUR(TIME('26:00:00'));
HOUR(TIME('1 02:00:00'))	HOUR(TIME('26:00:00'))
26	26
SELECT DAY(TIME('1 02:00:00')), DAY(TIME('26:00:00'));
DAY(TIME('1 02:00:00'))	DAY(TIME('26:00:00'))
2513
4	4
2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525
SELECT EXTRACT(HOUR FROM '1 02:00:00'), EXTRACT(HOUR FROM '26:00:00');
EXTRACT(HOUR FROM '1 02:00:00')	EXTRACT(HOUR FROM '26:00:00')
2	2
SELECT EXTRACT(HOUR FROM TIME'1 02:00:00'), EXTRACT(HOUR FROM TIME'26:00:00');
EXTRACT(HOUR FROM TIME'1 02:00:00')	EXTRACT(HOUR FROM TIME'26:00:00')
2	2
SELECT EXTRACT(HOUR FROM TIME('1 02:00:00')), EXTRACT(HOUR FROM TIME('26:00:00'));
EXTRACT(HOUR FROM TIME('1 02:00:00'))	EXTRACT(HOUR FROM TIME('26:00:00'))
2	2
SELECT EXTRACT(DAY FROM TIME('1 02:00:00')), EXTRACT(DAY FROM TIME('26:00:00'));
EXTRACT(DAY FROM TIME('1 02:00:00'))	EXTRACT(DAY FROM TIME('26:00:00'))
1	1
2526
SET timestamp=DEFAULT;
2527
#
2528 2529 2530 2531 2532 2533 2534
# MDEV-5458 RQG hits 'sql/tztime.cc:799: my_time_t sec_since_epoch(int, int, int, int, int, int): Assertion `mon > 0 && mon < 13' failed.'
#
SET TIMESTAMP=UNIX_TIMESTAMP('2014-01-22 18:19:20');
CREATE TABLE t1 (t TIME);
INSERT INTO t1 VALUES ('03:22:30'),('18:30:05');
SELECT CONVERT_TZ(GREATEST(t, CURRENT_DATE()), '+02:00', '+10:00') FROM t1;
CONVERT_TZ(GREATEST(t, CURRENT_DATE()), '+02:00', '+10:00')
2535 2536
2014-02-26 06:59:59
2014-02-26 06:59:59
2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549
Warnings:
Warning	1292	Truncated incorrect time value: '1296:00:00'
Warning	1292	Truncated incorrect time value: '1296:00:00'
SELECT GREATEST(t, CURRENT_DATE()) FROM t1;
GREATEST(t, CURRENT_DATE())
838:59:59
838:59:59
Warnings:
Warning	1292	Truncated incorrect time value: '1296:00:00'
Warning	1292	Truncated incorrect time value: '1296:00:00'
DROP TABLE t1;
SET TIMESTAMP=DEFAULT;
#
2550 2551 2552 2553 2554 2555 2556 2557 2558
# MDEV-5504 Server crashes in String::length on SELECT with MONTHNAME, GROUP BY, ROLLUP
#
CREATE TABLE t1 (i INT);
INSERT INTO t1 VALUES (1),(2);
SELECT 1 FROM t1 GROUP BY MONTHNAME(0) WITH ROLLUP;
1
1
1
DROP TABLE t1;
Sergei Golubchik's avatar
Sergei Golubchik committed
2559
#
2560 2561 2562 2563 2564 2565 2566
# MDEV-6099 Bad results for DATE_ADD(.., INTERVAL 2000000000000000000.0 SECOND)
#
SELECT DATE_ADD('2001-01-01 10:20:30',INTERVAL 250000000000.0 SECOND) AS c1, DATE_ADD('2001-01-01 10:20:30',INTERVAL 2000000000000000000.0 SECOND) AS c2;
c1	c2
9923-03-10 22:47:10.0	NULL
Warnings:
Warning	1292	Truncated incorrect DECIMAL value: '2000000000000000000.0'
Sergei Golubchik's avatar
Sergei Golubchik committed
2567
#
2568 2569 2570 2571 2572 2573 2574
# MDEV-4838 Wrong metadata for DATE_ADD('string', INVERVAL)
#
SELECT DATE_ADD('2011-01-02 12:13:14', INTERVAL 1 MINUTE);
Catalog	Database	Table	Table_alias	Column	Column_alias	Type	Length	Max length	Is_null	Flags	Decimals	Charsetnr
def					DATE_ADD('2011-01-02 12:13:14', INTERVAL 1 MINUTE)	254	19	19	Y	0	0	8
DATE_ADD('2011-01-02 12:13:14', INTERVAL 1 MINUTE)
2011-01-02 12:14:14
2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604
#
# MDEV-5450 Assertion `cached_field_ type == MYSQL_TYPE_STRING || ltime.time_type == MYSQL_TIMESTAMP_NONE || mysql_type_to_time_type(cached_field_type) == ltime.time_type' fails with IF, ISNULL, ADDDATE
#
CREATE TABLE t1 (a DATETIME, b DATE);
INSERT INTO t1 VALUES (NULL, '2012-12-21');
SELECT IF(1,ADDDATE(IFNULL(a,b),0),1) FROM t1;
IF(1,ADDDATE(IFNULL(a,b),0),1)
2012-12-21 00:00:00
SELECT CAST(ADDDATE(IFNULL(a,b),0) AS CHAR) FROM t1;
CAST(ADDDATE(IFNULL(a,b),0) AS CHAR)
2012-12-21 00:00:00
SELECT CAST(ADDDATE(COALESCE(a,b),0) AS CHAR) FROM t1;
CAST(ADDDATE(COALESCE(a,b),0) AS CHAR)
2012-12-21 00:00:00
SELECT CAST(ADDDATE(CASE WHEN 0 THEN a ELSE b END,0) AS CHAR) FROM t1;
CAST(ADDDATE(CASE WHEN 0 THEN a ELSE b END,0) AS CHAR)
2012-12-21 00:00:00
SELECT IF(1,ADDTIME(IFNULL(a,b),0),1) FROM t1;
IF(1,ADDTIME(IFNULL(a,b),0),1)
2012-12-21 00:00:00
SELECT CAST(ADDTIME(IFNULL(a,b),0) AS CHAR) FROM t1;
CAST(ADDTIME(IFNULL(a,b),0) AS CHAR)
2012-12-21 00:00:00
SELECT CAST(ADDTIME(COALESCE(a,b),0) AS CHAR) FROM t1;
CAST(ADDTIME(COALESCE(a,b),0) AS CHAR)
2012-12-21 00:00:00
SELECT CAST(ADDTIME(CASE WHEN 0 THEN a ELSE b END,0) AS CHAR) FROM t1;
CAST(ADDTIME(CASE WHEN 0 THEN a ELSE b END,0) AS CHAR)
2012-12-21 00:00:00
DROP TABLE t1;
2605
SET timestamp=unix_timestamp('2001-02-03 10:20:30');
2606 2607 2608 2609
CREATE TABLE t1 (a DATETIME, b TIME);
INSERT INTO t1 VALUES (NULL, '00:20:12');
SELECT IF(1,ADDDATE(IFNULL(a,b),0),1) FROM t1;
IF(1,ADDDATE(IFNULL(a,b),0),1)
2610
2001-02-03 00:20:12
2611 2612
SELECT CAST(ADDDATE(IFNULL(a,b),0) AS CHAR) FROM t1;
CAST(ADDDATE(IFNULL(a,b),0) AS CHAR)
2613
2001-02-03 00:20:12
2614 2615
SELECT CAST(ADDDATE(COALESCE(a,b),0) AS CHAR) FROM t1;
CAST(ADDDATE(COALESCE(a,b),0) AS CHAR)
2616
2001-02-03 00:20:12
2617 2618
SELECT CAST(ADDDATE(CASE WHEN 0 THEN a ELSE b END,0) AS CHAR) FROM t1;
CAST(ADDDATE(CASE WHEN 0 THEN a ELSE b END,0) AS CHAR)
2619
2001-02-03 00:20:12
2620 2621
SELECT IF(1,ADDTIME(IFNULL(a,b),0),1) FROM t1;
IF(1,ADDTIME(IFNULL(a,b),0),1)
2622
2001-02-03 00:20:12
2623 2624
SELECT CAST(ADDTIME(IFNULL(a,b),0) AS CHAR) FROM t1;
CAST(ADDTIME(IFNULL(a,b),0) AS CHAR)
2625
2001-02-03 00:20:12
2626 2627
SELECT CAST(ADDTIME(COALESCE(a,b),0) AS CHAR) FROM t1;
CAST(ADDTIME(COALESCE(a,b),0) AS CHAR)
2628
2001-02-03 00:20:12
2629 2630
SELECT CAST(ADDTIME(CASE WHEN 0 THEN a ELSE b END,0) AS CHAR) FROM t1;
CAST(ADDTIME(CASE WHEN 0 THEN a ELSE b END,0) AS CHAR)
2631
2001-02-03 00:20:12
2632
DROP TABLE t1;
2633
SET timestamp=DEFAULT;
2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646
#
# MDEV-5870 Assertion `ltime->neg == 0' fails with COALESCE, ADDDATE, MAKEDATE
#
CREATE TABLE t1 (dt DATETIME);
INSERT INTO t1 VALUES ('2003-05-13 19:36:05'), ('2012-12-12 09:20:06');
SELECT COALESCE(ADDDATE(MAKEDATE(2011,121), dt), '2006-09-12' ) FROM t1;
COALESCE(ADDDATE(MAKEDATE(2011,121), dt), '2006-09-12' )
2006-09-12
2006-09-12
Warnings:
Warning	1441	Datetime function: datetime field overflow
Warning	1441	Datetime function: datetime field overflow
DROP TABLE t1;
2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663
#
# MDEV-6101 Hybrid functions do not add CURRENT_DATE when converting TIME to DATETIME
#
SET timestamp=UNIX_TIMESTAMP('2014-04-15 01:02:03');
SELECT IF(1,TIME'10:20:30',DATE'2001-01-01');
IF(1,TIME'10:20:30',DATE'2001-01-01')
2014-04-15 10:20:30
SELECT IFNULL(TIME'10:20:30',DATE'2001-01-01');
IFNULL(TIME'10:20:30',DATE'2001-01-01')
2014-04-15 10:20:30
SELECT CASE WHEN 1 THEN TIME'10:20:30' ELSE DATE'2001-01-01' END;
CASE WHEN 1 THEN TIME'10:20:30' ELSE DATE'2001-01-01' END
2014-04-15 10:20:30
SELECT COALESCE(TIME'10:20:30',DATE'2001-01-01');
COALESCE(TIME'10:20:30',DATE'2001-01-01')
2014-04-15 10:20:30
SET timestamp=DEFAULT;
Sergei Golubchik's avatar
Sergei Golubchik committed
2664
#
2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678
# MDEV-5750 Assertion `ltime->year == 0' fails on a query with EXTRACT DAY_MINUTE and TIME column
#
CREATE TABLE t1 ( d DATE, t TIME );
INSERT INTO t1 VALUES ('2008-12-05','22:34:09'),('2005-03-27','14:26:02');
SELECT EXTRACT(DAY_MINUTE FROM GREATEST(t,d)), GREATEST(t,d) FROM t1;
EXTRACT(DAY_MINUTE FROM GREATEST(t,d))	GREATEST(t,d)
342259	838:59:59
342259	838:59:59
Warnings:
Warning	1292	Truncated incorrect time value: '9336:00:00'
Warning	1292	Truncated incorrect time value: '9336:00:00'
Warning	1292	Truncated incorrect time value: '2952:00:00'
Warning	1292	Truncated incorrect time value: '2952:00:00'
DROP TABLE t1;
2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702
#
# MDEV-7221 from_days fails after null value
#
CREATE TABLE t1 (
id INT(11) NOT NULL PRIMARY KEY,
date1 DATE NULL DEFAULT NULL
);
INSERT INTO t1 VALUES (12, '2011-05-12');
INSERT INTO t1 VALUES (13, NULL);
INSERT INTO t1 VALUES (14, '2009-10-23');
INSERT INTO t1 VALUES (15, '2014-10-30');
INSERT INTO t1 VALUES (16, NULL);
INSERT INTO t1 VALUES (17, NULL);
INSERT INTO t1 VALUES (18, '2010-10-13');
SELECT a.id,a.date1,FROM_DAYS(TO_DAYS(a.date1)-10) as date2, DATE_ADD(a.date1,INTERVAL -10 DAY),TO_DAYS(a.date1)-10 FROM t1 a ORDER BY a.id;
id	date1	date2	DATE_ADD(a.date1,INTERVAL -10 DAY)	TO_DAYS(a.date1)-10
12	2011-05-12	2011-05-02	2011-05-02	734624
13	NULL	NULL	NULL	NULL
14	2009-10-23	2009-10-13	2009-10-13	734058
15	2014-10-30	2014-10-20	2014-10-20	735891
16	NULL	NULL	NULL	NULL
17	NULL	NULL	NULL	NULL
18	2010-10-13	2010-10-03	2010-10-03	734413
DROP TABLE t1;
2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744
#
# Start of 10.0 tests
#
#
# MDEV-8205 timediff returns null when comparing decimal time to time string value
#
SELECT
TIMEDIFF('2014-01-01 00:00:00' , '2014-01-01 01:00:00' ) AS str_str,
TIMEDIFF('2014-01-01 00:00:00' , 20140101010000.000    ) AS str_dec,
TIMEDIFF(20140101000000.000    , 20140101010000.000    ) AS dec_dec,
TIMEDIFF(20140101000000.000    , '2014-01-01 01:00:00' ) AS dec_str;
str_str	str_dec	dec_dec	dec_str
-01:00:00	-01:00:00.000	-01:00:00.000	-01:00:00.000
SELECT
TIMEDIFF('2014-01-01 00:00:00' , '2014-01-02 01:00:00' ) AS str_str,
TIMEDIFF('2014-01-01 00:00:00' , 20140102010000.000    ) AS str_dec,
TIMEDIFF(20140101000000.000    , 20140102010000.000    ) AS dec_dec,
TIMEDIFF(20140101000000.000    , '2014-01-02 01:00:00' ) AS dec_str;
str_str	str_dec	dec_dec	dec_str
-25:00:00	-25:00:00.000	-25:00:00.000	-25:00:00.000
SELECT
TIMEDIFF('2014-01-01 00:00:00' , '2014-02-02 01:00:00' ) AS str_str,
TIMEDIFF('2014-01-01 00:00:00' , 20140202010000.000    ) AS str_dec,
TIMEDIFF(20140101000000.000    , 20140202010000.000    ) AS dec_dec,
TIMEDIFF(20140101000000.000    , '2014-02-02 01:00:00' ) AS dec_str;
str_str	str_dec	dec_dec	dec_str
-769:00:00	-769:00:00.000	-769:00:00.000	-769:00:00.000
SELECT
TIMEDIFF('2014-01-01 00:00:00' , '2014-03-02 01:00:00' ) AS str_str,
TIMEDIFF('2014-01-01 00:00:00' , 20140302010000.000    ) AS str_dec,
TIMEDIFF(20140101000000.000    , 20140302010000.000    ) AS dec_dec,
TIMEDIFF(20140101000000.000    , '2014-03-02 01:00:00' ) AS dec_str;
str_str	str_dec	dec_dec	dec_str
-838:59:59	-838:59:59.999	-838:59:59.999	-838:59:59.999
Warnings:
Warning	1292	Truncated incorrect time value: '-1441:00:00'
Warning	1292	Truncated incorrect time value: '-1441:00:00'
Warning	1292	Truncated incorrect time value: '-1441:00:00'
Warning	1292	Truncated incorrect time value: '-1441:00:00'
#
# End of 10.0 tests
#