~drizzle-trunk/drizzle/development

1 by brian
clean slate
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
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")
5
1996-01-01	31	1	5
6
select period_add("9602",-12),period_diff(199505,"9404") ;
7
period_add("9602",-12)	period_diff(199505,"9404")
8
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.000000	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.000000
15
select sec_to_time(9001),sec_to_time(9001)+0,time_to_sec("15:12:22"),
16
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.000000	54742	00:04:57
19
select sec_to_time(time_to_sec('-838:59:59'));
20
sec_to_time(time_to_sec('-838:59:59'))
21
-838:59:59
22
select now()-curdate()*1000000-curtime();
23
now()-curdate()*1000000-curtime()
24
0.000000
25
select strcmp(current_timestamp(),concat(current_date()," ",current_time()));
26
strcmp(current_timestamp(),concat(current_date()," ",current_time()))
27
0
28
select strcmp(localtime(),concat(current_date()," ",current_time()));
29
strcmp(localtime(),concat(current_date()," ",current_time()))
30
0
31
select strcmp(localtimestamp(),concat(current_date()," ",current_time()));
32
strcmp(localtimestamp(),concat(current_date()," ",current_time()))
33
0
34
select date_format("1997-01-02 03:04:05", "%M %W %D %Y %y %m %d %h %i %s %w");
35
date_format("1997-01-02 03:04:05", "%M %W %D %Y %y %m %d %h %i %s %w")
36
January Thursday 2nd 1997 97 01 02 03 04 05 4
37
select date_format("1997-01-02", concat("%M %W %D ","%Y %y %m %d %h %i %s %w"));
38
date_format("1997-01-02", concat("%M %W %D ","%Y %y %m %d %h %i %s %w"))
39
January Thursday 2nd 1997 97 01 02 12 00 00 4
40
select dayofmonth("1997-01-02"),dayofmonth(19970323);
41
dayofmonth("1997-01-02")	dayofmonth(19970323)
42
2	23
43
select month("1997-01-02"),year("98-02-03"),dayofyear("1997-12-31");
44
month("1997-01-02")	year("98-02-03")	dayofyear("1997-12-31")
45
1	1998	365
46
select month("2001-02-00"),year("2001-00-00");
47
month("2001-02-00")	year("2001-00-00")
48
2	2001
49
select DAYOFYEAR("1997-03-03"), WEEK("1998-03-03"), QUARTER(980303);
50
DAYOFYEAR("1997-03-03")	WEEK("1998-03-03")	QUARTER(980303)
51
62	9	1
52
select HOUR("1997-03-03 23:03:22"), MINUTE("23:03:22"), SECOND(230322);
53
HOUR("1997-03-03 23:03:22")	MINUTE("23:03:22")	SECOND(230322)
54
23	3	22
55
select week(19980101),week(19970101),week(19980101,1),week(19970101,1);
56
week(19980101)	week(19970101)	week(19980101,1)	week(19970101,1)
57
0	0	1	1
58
select week(19981231),week(19971231),week(19981231,1),week(19971231,1);
59
week(19981231)	week(19971231)	week(19981231,1)	week(19971231,1)
60
52	52	53	53
61
select week(19950101),week(19950101,1);
62
week(19950101)	week(19950101,1)
63
1	0
64
select yearweek('1981-12-31',1),yearweek('1982-01-01',1),yearweek('1982-12-31',1),yearweek('1983-01-01',1);
65
yearweek('1981-12-31',1)	yearweek('1982-01-01',1)	yearweek('1982-12-31',1)	yearweek('1983-01-01',1)
66
198153	198153	198252	198252
67
select yearweek('1987-01-01',1),yearweek('1987-01-01');
68
yearweek('1987-01-01',1)	yearweek('1987-01-01')
69
198701	198652
70
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';
71
2000	2001	2002	2003	2004	2005	2006
72
0	0	0	0	0	0	1
73
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';
74
2000	2001	2002	2003	2004	2005	2006
75
1	0	1	1	1	1	1
76
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';
77
2000	2001	2002	2003	2004	2005	2006
78
0	1	1	1	1	0	0
79
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';
80
2000	2001	2002	2003	2004	2005	2006
81
1	1	1	2	2	1	1
82
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';
83
2000	2001	2002	2003	2004	2005	2006
84
199952	200053	200152	200252	200352	200452	200601
85
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';
86
2000	2001	2002	2003	2004	2005	2006
87
200001	200053	200201	200301	200401	200501	200601
88
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';
89
2000	2001	2002	2003	2004	2005	2006
90
199952	200101	200201	200301	200401	200453	200552
91
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';
92
2000	2001	2002	2003	2004	2005	2006
93
200001	200101	200201	200302	200402	200501	200601
94
select week(19981231,2), week(19981231,3), week(20000101,2), week(20000101,3);
95
week(19981231,2)	week(19981231,3)	week(20000101,2)	week(20000101,3)
96
52	53	52	52
97
select week(20001231,2),week(20001231,3);
98
week(20001231,2)	week(20001231,3)
99
53	52
100
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';
101
0	1	2	3	4	5	6	7
102
52	53	52	53	52	52	52	52
103
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';
104
0	1	2	3	4	5	6	7
105
0	0	52	52	0	0	52	52
106
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';
107
0	1	2	3	4	5	6	7
108
1	1	1	1	1	1	1	1
109
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';
110
0	1	2	3	4	5	6	7
111
53	52	53	52	53	52	1	52
112
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';
113
0	1	2	3	4	5	6	7
114
0	1	53	1	1	1	1	1
115
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);
116
yearweek(20001231,0)	yearweek(20001231,1)	yearweek(20001231,2)	yearweek(20001231,3)	yearweek(20001231,4)	yearweek(20001231,5)	yearweek(20001231,6)	yearweek(20001231,7)
117
200053	200052	200053	200052	200101	200052	200101	200052
118
set default_week_format = 6;
119
select week(20001231), week(20001231,6);
120
week(20001231)	week(20001231,6)
121
1	1
122
set default_week_format = 0;
123
set default_week_format = 2;
124
select week(20001231),week(20001231,2),week(20001231,0);
125
week(20001231)	week(20001231,2)	week(20001231,0)
126
53	53	53
127
set default_week_format = 0;
128
select date_format('1998-12-31','%x-%v'),date_format('1999-01-01','%x-%v');
129
date_format('1998-12-31','%x-%v')	date_format('1999-01-01','%x-%v')
130
1998-53	1998-53
131
select date_format('1999-12-31','%x-%v'),date_format('2000-01-01','%x-%v');
132
date_format('1999-12-31','%x-%v')	date_format('2000-01-01','%x-%v')
133
1999-52	1999-52
134
select dayname("1962-03-03"),dayname("1962-03-03")+0;
135
dayname("1962-03-03")	dayname("1962-03-03")+0
136
Saturday	5
137
select monthname("1972-03-04"),monthname("1972-03-04")+0;
138
monthname("1972-03-04")	monthname("1972-03-04")+0
139
March	3
140
select time_format(19980131000000,'%H|%I|%k|%l|%i|%p|%r|%S|%T');
141
time_format(19980131000000,'%H|%I|%k|%l|%i|%p|%r|%S|%T')
142
00|12|0|12|00|AM|12:00:00 AM|00|00:00:00
143
select time_format(19980131010203,'%H|%I|%k|%l|%i|%p|%r|%S|%T');
144
time_format(19980131010203,'%H|%I|%k|%l|%i|%p|%r|%S|%T')
145
01|01|1|1|02|AM|01:02:03 AM|03|01:02:03
146
select time_format(19980131131415,'%H|%I|%k|%l|%i|%p|%r|%S|%T');
147
time_format(19980131131415,'%H|%I|%k|%l|%i|%p|%r|%S|%T')
148
13|01|13|1|14|PM|01:14:15 PM|15|13:14:15
149
select time_format(19980131010015,'%H|%I|%k|%l|%i|%p|%r|%S|%T');
150
time_format(19980131010015,'%H|%I|%k|%l|%i|%p|%r|%S|%T')
151
01|01|1|1|00|AM|01:00:15 AM|15|01:00:15
152
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');
153
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')
154
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
155
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');
156
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')
157
NULL
158
select date_add("1997-12-31 23:59:59",INTERVAL 1 SECOND);
159
date_add("1997-12-31 23:59:59",INTERVAL 1 SECOND)
160
1998-01-01 00:00:00
161
select date_add("1997-12-31 23:59:59",INTERVAL 1 MINUTE);
162
date_add("1997-12-31 23:59:59",INTERVAL 1 MINUTE)
163
1998-01-01 00:00:59
164
select date_add("1997-12-31 23:59:59",INTERVAL 1 HOUR);
165
date_add("1997-12-31 23:59:59",INTERVAL 1 HOUR)
166
1998-01-01 00:59:59
167
select date_add("1997-12-31 23:59:59",INTERVAL 1 DAY);
168
date_add("1997-12-31 23:59:59",INTERVAL 1 DAY)
169
1998-01-01 23:59:59
170
select date_add("1997-12-31 23:59:59",INTERVAL 1 MONTH);
171
date_add("1997-12-31 23:59:59",INTERVAL 1 MONTH)
172
1998-01-31 23:59:59
173
select date_add("1997-12-31 23:59:59",INTERVAL 1 YEAR);
174
date_add("1997-12-31 23:59:59",INTERVAL 1 YEAR)
175
1998-12-31 23:59:59
176
select date_add("1997-12-31 23:59:59",INTERVAL "1:1" MINUTE_SECOND);
177
date_add("1997-12-31 23:59:59",INTERVAL "1:1" MINUTE_SECOND)
178
1998-01-01 00:01:00
179
select date_add("1997-12-31 23:59:59",INTERVAL "1:1" HOUR_MINUTE);
180
date_add("1997-12-31 23:59:59",INTERVAL "1:1" HOUR_MINUTE)
181
1998-01-01 01:00:59
182
select date_add("1997-12-31 23:59:59",INTERVAL "1:1" DAY_HOUR);
183
date_add("1997-12-31 23:59:59",INTERVAL "1:1" DAY_HOUR)
184
1998-01-02 00:59:59
185
select date_add("1997-12-31 23:59:59",INTERVAL "1 1" YEAR_MONTH);
186
date_add("1997-12-31 23:59:59",INTERVAL "1 1" YEAR_MONTH)
187
1999-01-31 23:59:59
188
select date_add("1997-12-31 23:59:59",INTERVAL "1:1:1" HOUR_SECOND);
189
date_add("1997-12-31 23:59:59",INTERVAL "1:1:1" HOUR_SECOND)
190
1998-01-01 01:01:00
191
select date_add("1997-12-31 23:59:59",INTERVAL "1 1:1" DAY_MINUTE);
192
date_add("1997-12-31 23:59:59",INTERVAL "1 1:1" DAY_MINUTE)
193
1998-01-02 01:00:59
194
select date_add("1997-12-31 23:59:59",INTERVAL "1 1:1:1" DAY_SECOND);
195
date_add("1997-12-31 23:59:59",INTERVAL "1 1:1:1" DAY_SECOND)
196
1998-01-02 01:01:00
197
select date_sub("1998-01-01 00:00:00",INTERVAL 1 SECOND);
198
date_sub("1998-01-01 00:00:00",INTERVAL 1 SECOND)
199
1997-12-31 23:59:59
200
select date_sub("1998-01-01 00:00:00",INTERVAL 1 MINUTE);
201
date_sub("1998-01-01 00:00:00",INTERVAL 1 MINUTE)
202
1997-12-31 23:59:00
203
select date_sub("1998-01-01 00:00:00",INTERVAL 1 HOUR);
204
date_sub("1998-01-01 00:00:00",INTERVAL 1 HOUR)
205
1997-12-31 23:00:00
206
select date_sub("1998-01-01 00:00:00",INTERVAL 1 DAY);
207
date_sub("1998-01-01 00:00:00",INTERVAL 1 DAY)
208
1997-12-31 00:00:00
209
select date_sub("1998-01-01 00:00:00",INTERVAL 1 MONTH);
210
date_sub("1998-01-01 00:00:00",INTERVAL 1 MONTH)
211
1997-12-01 00:00:00
212
select date_sub("1998-01-01 00:00:00",INTERVAL 1 YEAR);
213
date_sub("1998-01-01 00:00:00",INTERVAL 1 YEAR)
214
1997-01-01 00:00:00
215
select date_sub("1998-01-01 00:00:00",INTERVAL "1:1" MINUTE_SECOND);
216
date_sub("1998-01-01 00:00:00",INTERVAL "1:1" MINUTE_SECOND)
217
1997-12-31 23:58:59
218
select date_sub("1998-01-01 00:00:00",INTERVAL "1:1" HOUR_MINUTE);
219
date_sub("1998-01-01 00:00:00",INTERVAL "1:1" HOUR_MINUTE)
220
1997-12-31 22:59:00
221
select date_sub("1998-01-01 00:00:00",INTERVAL "1:1" DAY_HOUR);
222
date_sub("1998-01-01 00:00:00",INTERVAL "1:1" DAY_HOUR)
223
1997-12-30 23:00:00
224
select date_sub("1998-01-01 00:00:00",INTERVAL "1 1" YEAR_MONTH);
225
date_sub("1998-01-01 00:00:00",INTERVAL "1 1" YEAR_MONTH)
226
1996-12-01 00:00:00
227
select date_sub("1998-01-01 00:00:00",INTERVAL "1:1:1" HOUR_SECOND);
228
date_sub("1998-01-01 00:00:00",INTERVAL "1:1:1" HOUR_SECOND)
229
1997-12-31 22:58:59
230
select date_sub("1998-01-01 00:00:00",INTERVAL "1 1:1" DAY_MINUTE);
231
date_sub("1998-01-01 00:00:00",INTERVAL "1 1:1" DAY_MINUTE)
232
1997-12-30 22:59:00
233
select date_sub("1998-01-01 00:00:00",INTERVAL "1 1:1:1" DAY_SECOND);
234
date_sub("1998-01-01 00:00:00",INTERVAL "1 1:1:1" DAY_SECOND)
235
1997-12-30 22:58:59
236
select date_add("1997-12-31 23:59:59",INTERVAL 100000 SECOND);
237
date_add("1997-12-31 23:59:59",INTERVAL 100000 SECOND)
238
1998-01-02 03:46:39
239
select date_add("1997-12-31 23:59:59",INTERVAL -100000 MINUTE);
240
date_add("1997-12-31 23:59:59",INTERVAL -100000 MINUTE)
241
1997-10-23 13:19:59
242
select date_add("1997-12-31 23:59:59",INTERVAL 100000 HOUR);
243
date_add("1997-12-31 23:59:59",INTERVAL 100000 HOUR)
244
2009-05-29 15:59:59
245
select date_add("1997-12-31 23:59:59",INTERVAL -100000 DAY);
246
date_add("1997-12-31 23:59:59",INTERVAL -100000 DAY)
247
1724-03-17 23:59:59
248
select date_add("1997-12-31 23:59:59",INTERVAL 100000 MONTH);
249
date_add("1997-12-31 23:59:59",INTERVAL 100000 MONTH)
250
NULL
251
Warnings:
252
Warning	1441	Datetime function: datetime field overflow
253
select date_add("1997-12-31 23:59:59",INTERVAL -100000 YEAR);
254
date_add("1997-12-31 23:59:59",INTERVAL -100000 YEAR)
255
NULL
256
Warnings:
257
Warning	1441	Datetime function: datetime field overflow
258
select date_add("1997-12-31 23:59:59",INTERVAL "10000:1" MINUTE_SECOND);
259
date_add("1997-12-31 23:59:59",INTERVAL "10000:1" MINUTE_SECOND)
260
1998-01-07 22:40:00
261
select date_add("1997-12-31 23:59:59",INTERVAL "-10000:1" HOUR_MINUTE);
262
date_add("1997-12-31 23:59:59",INTERVAL "-10000:1" HOUR_MINUTE)
263
1996-11-10 07:58:59
264
select date_add("1997-12-31 23:59:59",INTERVAL "10000:1" DAY_HOUR);
265
date_add("1997-12-31 23:59:59",INTERVAL "10000:1" DAY_HOUR)
266
2025-05-19 00:59:59
267
select date_add("1997-12-31 23:59:59",INTERVAL "-100 1" YEAR_MONTH);
268
date_add("1997-12-31 23:59:59",INTERVAL "-100 1" YEAR_MONTH)
269
1897-11-30 23:59:59
270
select date_add("1997-12-31 23:59:59",INTERVAL "10000:99:99" HOUR_SECOND);
271
date_add("1997-12-31 23:59:59",INTERVAL "10000:99:99" HOUR_SECOND)
272
1999-02-21 17:40:38
273
select date_add("1997-12-31 23:59:59",INTERVAL " -10000 99:99" DAY_MINUTE);
274
date_add("1997-12-31 23:59:59",INTERVAL " -10000 99:99" DAY_MINUTE)
275
1970-08-11 19:20:59
276
select date_add("1997-12-31 23:59:59",INTERVAL "10000 99:99:99" DAY_SECOND);
277
date_add("1997-12-31 23:59:59",INTERVAL "10000 99:99:99" DAY_SECOND)
278
2025-05-23 04:40:38
279
select "1997-12-31 23:59:59" + INTERVAL 1 SECOND;
280
"1997-12-31 23:59:59" + INTERVAL 1 SECOND
281
1998-01-01 00:00:00
282
select INTERVAL 1 DAY + "1997-12-31";
283
INTERVAL 1 DAY + "1997-12-31"
284
1998-01-01
285
select "1998-01-01 00:00:00" - INTERVAL 1 SECOND;
286
"1998-01-01 00:00:00" - INTERVAL 1 SECOND
287
1997-12-31 23:59:59
288
select date_sub("1998-01-02",INTERVAL 31 DAY);
289
date_sub("1998-01-02",INTERVAL 31 DAY)
290
1997-12-02
291
select date_add("1997-12-31",INTERVAL 1 SECOND);
292
date_add("1997-12-31",INTERVAL 1 SECOND)
293
1997-12-31 00:00:01
294
select date_add("1997-12-31",INTERVAL 1 DAY);
295
date_add("1997-12-31",INTERVAL 1 DAY)
296
1998-01-01
297
select date_add(NULL,INTERVAL 100000 SECOND);
298
date_add(NULL,INTERVAL 100000 SECOND)
299
NULL
300
select date_add("1997-12-31 23:59:59",INTERVAL NULL SECOND);
301
date_add("1997-12-31 23:59:59",INTERVAL NULL SECOND)
302
NULL
303
select date_add("1997-12-31 23:59:59",INTERVAL NULL MINUTE_SECOND);
304
date_add("1997-12-31 23:59:59",INTERVAL NULL MINUTE_SECOND)
305
NULL
306
select date_add("9999-12-31 23:59:59",INTERVAL 1 SECOND);
307
date_add("9999-12-31 23:59:59",INTERVAL 1 SECOND)
308
NULL
309
Warnings:
310
Warning	1441	Datetime function: datetime field overflow
311
select date_sub("0000-00-00 00:00:00",INTERVAL 1 SECOND);
312
date_sub("0000-00-00 00:00:00",INTERVAL 1 SECOND)
313
NULL
314
Warnings:
315
Warning	1292	Incorrect datetime value: '0000-00-00 00:00:00'
316
select date_add('1998-01-30',Interval 1 month);
317
date_add('1998-01-30',Interval 1 month)
318
1998-02-28
319
select date_add('1998-01-30',Interval '2:1' year_month);
320
date_add('1998-01-30',Interval '2:1' year_month)
321
2000-02-29
322
select date_add('1996-02-29',Interval '1' year);
323
date_add('1996-02-29',Interval '1' year)
324
1997-02-28
325
select extract(YEAR FROM "1999-01-02 10:11:12");
326
extract(YEAR FROM "1999-01-02 10:11:12")
327
1999
328
select extract(YEAR_MONTH FROM "1999-01-02");
329
extract(YEAR_MONTH FROM "1999-01-02")
330
199901
331
select extract(DAY FROM "1999-01-02");
332
extract(DAY FROM "1999-01-02")
333
2
334
select extract(DAY_HOUR FROM "1999-01-02 10:11:12");
335
extract(DAY_HOUR FROM "1999-01-02 10:11:12")
336
210
337
select extract(DAY_MINUTE FROM "02 10:11:12");
338
extract(DAY_MINUTE FROM "02 10:11:12")
339
21011
340
select extract(DAY_SECOND FROM "225 10:11:12");
341
extract(DAY_SECOND FROM "225 10:11:12")
342
8385959
343
Warnings:
344
Warning	1292	Truncated incorrect time value: '225 10:11:12'
345
select extract(HOUR FROM "1999-01-02 10:11:12");
346
extract(HOUR FROM "1999-01-02 10:11:12")
347
10
348
select extract(HOUR_MINUTE FROM "10:11:12");
349
extract(HOUR_MINUTE FROM "10:11:12")
350
1011
351
select extract(HOUR_SECOND FROM "10:11:12");
352
extract(HOUR_SECOND FROM "10:11:12")
353
101112
354
select extract(MINUTE FROM "10:11:12");
355
extract(MINUTE FROM "10:11:12")
356
11
357
select extract(MINUTE_SECOND FROM "10:11:12");
358
extract(MINUTE_SECOND FROM "10:11:12")
359
1112
360
select extract(SECOND FROM "1999-01-02 10:11:12");
361
extract(SECOND FROM "1999-01-02 10:11:12")
362
12
363
select extract(MONTH FROM "2001-02-00");
364
extract(MONTH FROM "2001-02-00")
365
2
366
SELECT EXTRACT(QUARTER FROM '2004-01-15') AS quarter;
367
quarter
368
1
369
SELECT EXTRACT(QUARTER FROM '2004-02-15') AS quarter;
370
quarter
371
1
372
SELECT EXTRACT(QUARTER FROM '2004-03-15') AS quarter;
373
quarter
374
1
375
SELECT EXTRACT(QUARTER FROM '2004-04-15') AS quarter;
376
quarter
377
2
378
SELECT EXTRACT(QUARTER FROM '2004-05-15') AS quarter;
379
quarter
380
2
381
SELECT EXTRACT(QUARTER FROM '2004-06-15') AS quarter;
382
quarter
383
2
384
SELECT EXTRACT(QUARTER FROM '2004-07-15') AS quarter;
385
quarter
386
3
387
SELECT EXTRACT(QUARTER FROM '2004-08-15') AS quarter;
388
quarter
389
3
390
SELECT EXTRACT(QUARTER FROM '2004-09-15') AS quarter;
391
quarter
392
3
393
SELECT EXTRACT(QUARTER FROM '2004-10-15') AS quarter;
394
quarter
395
4
396
SELECT EXTRACT(QUARTER FROM '2004-11-15') AS quarter;
397
quarter
398
4
399
SELECT EXTRACT(QUARTER FROM '2004-12-15') AS quarter;
400
quarter
401
4
402
SELECT DATE_SUB(str_to_date('9999-12-31 00:01:00','%Y-%m-%d %H:%i:%s'), INTERVAL 1 MINUTE);
403
DATE_SUB(str_to_date('9999-12-31 00:01:00','%Y-%m-%d %H:%i:%s'), INTERVAL 1 MINUTE)
404
9999-12-31 00:00:00
405
SELECT DATE_ADD(str_to_date('9999-12-30 23:59:00','%Y-%m-%d %H:%i:%s'), INTERVAL 1 MINUTE);
406
DATE_ADD(str_to_date('9999-12-30 23:59:00','%Y-%m-%d %H:%i:%s'), INTERVAL 1 MINUTE)
407
9999-12-31 00:00:00
408
SELECT "1900-01-01 00:00:00" + INTERVAL 2147483648 SECOND;
409
"1900-01-01 00:00:00" + INTERVAL 2147483648 SECOND
410
1968-01-20 03:14:08
411
SELECT "1900-01-01 00:00:00" + INTERVAL "1:2147483647" MINUTE_SECOND;
412
"1900-01-01 00:00:00" + INTERVAL "1:2147483647" MINUTE_SECOND
413
1968-01-20 03:15:07
414
SELECT "1900-01-01 00:00:00" + INTERVAL "100000000:214748364700" MINUTE_SECOND;
415
"1900-01-01 00:00:00" + INTERVAL "100000000:214748364700" MINUTE_SECOND
416
8895-03-27 22:11:40
417
SELECT "1900-01-01 00:00:00" + INTERVAL 1<<37 SECOND;
418
"1900-01-01 00:00:00" + INTERVAL 1<<37 SECOND
419
6255-04-08 15:04:32
420
SELECT "1900-01-01 00:00:00" + INTERVAL 1<<31 MINUTE;
421
"1900-01-01 00:00:00" + INTERVAL 1<<31 MINUTE
422
5983-01-24 02:08:00
423
SELECT "1900-01-01 00:00:00" + INTERVAL 1<<20 HOUR;
424
"1900-01-01 00:00:00" + INTERVAL 1<<20 HOUR
425
2019-08-15 16:00:00
426
SELECT "1900-01-01 00:00:00" + INTERVAL 1<<38 SECOND;
427
"1900-01-01 00:00:00" + INTERVAL 1<<38 SECOND
428
NULL
429
Warnings:
430
Warning	1441	Datetime function: datetime field overflow
431
SELECT "1900-01-01 00:00:00" + INTERVAL 1<<33 MINUTE;
432
"1900-01-01 00:00:00" + INTERVAL 1<<33 MINUTE
433
NULL
434
Warnings:
435
Warning	1441	Datetime function: datetime field overflow
436
SELECT "1900-01-01 00:00:00" + INTERVAL 1<<30 HOUR;
437
"1900-01-01 00:00:00" + INTERVAL 1<<30 HOUR
438
NULL
439
Warnings:
440
Warning	1441	Datetime function: datetime field overflow
441
SELECT "1900-01-01 00:00:00" + INTERVAL "1000000000:214748364700" MINUTE_SECOND;
442
"1900-01-01 00:00:00" + INTERVAL "1000000000:214748364700" MINUTE_SECOND
443
NULL
444
Warnings:
445
Warning	1441	Datetime function: datetime field overflow
446
create table t1 (ctime varchar(20));
447
insert into t1 values ('2001-01-12 12:23:40');
448
select ctime, hour(ctime) from t1;
449
ctime	hour(ctime)
450
2001-01-12 12:23:40	12
451
select ctime from t1 where extract(MONTH FROM ctime) = 1 AND extract(YEAR FROM ctime) = 2001;
452
ctime
453
2001-01-12 12:23:40
454
drop table t1;
455
create table t1 (id int);
456
create table t2 (id int, date date);
457
insert into t1 values (1);
458
insert into t2 values (1, "0000-00-00");
459
insert into t1 values (2);
460
insert into t2 values (2, "2000-01-01");
461
select monthname(date) from t1 inner join t2 on t1.id = t2.id;
462
monthname(date)
463
NULL
464
January
465
select monthname(date) from t1 inner join t2 on t1.id = t2.id order by t1.id;
466
monthname(date)
467
NULL
468
January
469
drop table t1,t2;
470
CREATE TABLE t1 (updated text) ENGINE=MyISAM;
471
INSERT INTO t1 VALUES ('');
472
SELECT month(updated) from t1;
473
month(updated)
474
NULL
475
Warnings:
476
Warning	1292	Incorrect datetime value: ''
477
SELECT year(updated) from t1;
478
year(updated)
479
NULL
480
Warnings:
481
Warning	1292	Incorrect datetime value: ''
482
drop table t1;
483
create table t1 (d date, dt datetime, t timestamp, c char(10));
484
insert into t1 values ("0000-00-00", "0000-00-00", "0000-00-00", "0000-00-00");
485
select dayofyear("0000-00-00"),dayofyear(d),dayofyear(dt),dayofyear(t),dayofyear(c) from t1;
486
dayofyear("0000-00-00")	dayofyear(d)	dayofyear(dt)	dayofyear(t)	dayofyear(c)
487
NULL	NULL	NULL	NULL	NULL
488
Warnings:
489
Warning	1292	Incorrect datetime value: '0000-00-00'
490
Warning	1292	Incorrect datetime value: '0000-00-00'
491
select dayofmonth("0000-00-00"),dayofmonth(d),dayofmonth(dt),dayofmonth(t),dayofmonth(c) from t1;
492
dayofmonth("0000-00-00")	dayofmonth(d)	dayofmonth(dt)	dayofmonth(t)	dayofmonth(c)
493
0	0	0	0	0
494
select month("0000-00-00"),month(d),month(dt),month(t),month(c) from t1;
495
month("0000-00-00")	month(d)	month(dt)	month(t)	month(c)
496
0	0	0	0	0
497
select quarter("0000-00-00"),quarter(d),quarter(dt),quarter(t),quarter(c) from t1;
498
quarter("0000-00-00")	quarter(d)	quarter(dt)	quarter(t)	quarter(c)
499
0	0	0	0	0
500
select week("0000-00-00"),week(d),week(dt),week(t),week(c) from t1;
501
week("0000-00-00")	week(d)	week(dt)	week(t)	week(c)
502
NULL	NULL	NULL	NULL	NULL
503
Warnings:
504
Warning	1292	Incorrect datetime value: '0000-00-00'
505
Warning	1292	Incorrect datetime value: '0000-00-00'
506
select year("0000-00-00"),year(d),year(dt),year(t),year(c) from t1;
507
year("0000-00-00")	year(d)	year(dt)	year(t)	year(c)
508
0	0	0	0	0
509
select yearweek("0000-00-00"),yearweek(d),yearweek(dt),yearweek(t),yearweek(c) from t1;
510
yearweek("0000-00-00")	yearweek(d)	yearweek(dt)	yearweek(t)	yearweek(c)
511
NULL	NULL	NULL	NULL	NULL
512
Warnings:
513
Warning	1292	Incorrect datetime value: '0000-00-00'
514
Warning	1292	Incorrect datetime value: '0000-00-00'
515
select to_days("0000-00-00"),to_days(d),to_days(dt),to_days(t),to_days(c) from t1;
516
to_days("0000-00-00")	to_days(d)	to_days(dt)	to_days(t)	to_days(c)
517
NULL	NULL	NULL	NULL	NULL
518
Warnings:
519
Warning	1292	Incorrect datetime value: '0000-00-00'
520
Warning	1292	Incorrect datetime value: '0000-00-00'
521
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;
522
extract(MONTH FROM "0000-00-00")	extract(MONTH FROM d)	extract(MONTH FROM dt)	extract(MONTH FROM t)	extract(MONTH FROM c)
523
0	0	0	0	0
524
drop table t1;
525
CREATE TABLE t1 ( start datetime default NULL);
526
INSERT INTO t1 VALUES ('2002-10-21 00:00:00'),('2002-10-28 00:00:00'),('2002-11-04 00:00:00');
527
CREATE TABLE t2 ( ctime1 timestamp NOT NULL, ctime2 timestamp NOT NULL);
528
INSERT INTO t2 VALUES (20021029165106,20021105164731);
529
CREATE TABLE t3 (ctime1 char(19) NOT NULL, ctime2 char(19) NOT NULL);
530
INSERT INTO t3 VALUES ("2002-10-29 16:51:06","2002-11-05 16:47:31");
531
select * from t1, t2 where t1.start between t2.ctime1 and t2.ctime2;
532
start	ctime1	ctime2
533
2002-11-04 00:00:00	2002-10-29 16:51:06	2002-11-05 16:47:31
534
select * from t1, t2 where t1.start >= t2.ctime1 and t1.start <= t2.ctime2;
535
start	ctime1	ctime2
536
2002-11-04 00:00:00	2002-10-29 16:51:06	2002-11-05 16:47:31
537
select * from t1, t3 where t1.start between t3.ctime1 and t3.ctime2;
538
start	ctime1	ctime2
539
2002-11-04 00:00:00	2002-10-29 16:51:06	2002-11-05 16:47:31
540
drop table t1,t2,t3;
541
select @a:=FROM_UNIXTIME(1);
542
@a:=FROM_UNIXTIME(1)
543
1970-01-01 03:00:01
544
select unix_timestamp(@a);
545
unix_timestamp(@a)
546
1
547
select unix_timestamp('1969-12-01 19:00:01');
548
unix_timestamp('1969-12-01 19:00:01')
549
0
550
select from_unixtime(-1);
551
from_unixtime(-1)
552
NULL
553
select from_unixtime(2147483647);
554
from_unixtime(2147483647)
555
2038-01-19 06:14:07
556
select from_unixtime(2147483648);
557
from_unixtime(2147483648)
558
NULL
559
select from_unixtime(0);
560
from_unixtime(0)
561
1970-01-01 03:00:00
562
select unix_timestamp(from_unixtime(2147483647));
563
unix_timestamp(from_unixtime(2147483647))
564
2147483647
565
select unix_timestamp(from_unixtime(2147483648));
566
unix_timestamp(from_unixtime(2147483648))
567
NULL
568
select unix_timestamp('2039-01-20 01:00:00');
569
unix_timestamp('2039-01-20 01:00:00')
570
0
571
select unix_timestamp('1968-01-20 01:00:00');
572
unix_timestamp('1968-01-20 01:00:00')
573
0
574
select unix_timestamp('2038-02-10 01:00:00');
575
unix_timestamp('2038-02-10 01:00:00')
576
0
577
select unix_timestamp('1969-11-20 01:00:00');
578
unix_timestamp('1969-11-20 01:00:00')
579
0
580
select unix_timestamp('2038-01-20 01:00:00');
581
unix_timestamp('2038-01-20 01:00:00')
582
0
583
select unix_timestamp('1969-12-30 01:00:00');
584
unix_timestamp('1969-12-30 01:00:00')
585
0
586
select unix_timestamp('2038-01-17 12:00:00');
587
unix_timestamp('2038-01-17 12:00:00')
588
2147331600
589
select unix_timestamp('1970-01-01 03:00:01');
590
unix_timestamp('1970-01-01 03:00:01')
591
1
592
select unix_timestamp('2038-01-19 07:14:07');
593
unix_timestamp('2038-01-19 07:14:07')
594
0
595
CREATE TABLE t1 (datetime datetime, timestamp timestamp, date date, time time);
596
INSERT INTO t1 values ("2001-01-02 03:04:05", "2002-01-02 03:04:05", "2003-01-02", "06:07:08");
597
SELECT * from t1;
598
datetime	timestamp	date	time
599
2001-01-02 03:04:05	2002-01-02 03:04:05	2003-01-02	06:07:08
600
select date_add("1997-12-31",INTERVAL 1 SECOND);
601
date_add("1997-12-31",INTERVAL 1 SECOND)
602
1997-12-31 00:00:01
603
select date_add("1997-12-31",INTERVAL "1 1" YEAR_MONTH);
604
date_add("1997-12-31",INTERVAL "1 1" YEAR_MONTH)
605
1999-01-31
606
select date_add(datetime, INTERVAL 1 SECOND) from t1;
607
date_add(datetime, INTERVAL 1 SECOND)
608
2001-01-02 03:04:06
609
select date_add(datetime, INTERVAL 1 YEAR) from t1;
610
date_add(datetime, INTERVAL 1 YEAR)
611
2002-01-02 03:04:05
612
select date_add(date,INTERVAL 1 SECOND) from t1;
613
date_add(date,INTERVAL 1 SECOND)
614
2003-01-02 00:00:01
615
select date_add(date,INTERVAL 1 MINUTE) from t1;
616
date_add(date,INTERVAL 1 MINUTE)
617
2003-01-02 00:01:00
618
select date_add(date,INTERVAL 1 HOUR) from t1;
619
date_add(date,INTERVAL 1 HOUR)
620
2003-01-02 01:00:00
621
select date_add(date,INTERVAL 1 DAY) from t1;
622
date_add(date,INTERVAL 1 DAY)
623
2003-01-03
624
select date_add(date,INTERVAL 1 MONTH) from t1;
625
date_add(date,INTERVAL 1 MONTH)
626
2003-02-02
627
select date_add(date,INTERVAL 1 YEAR) from t1;
628
date_add(date,INTERVAL 1 YEAR)
629
2004-01-02
630
select date_add(date,INTERVAL "1:1" MINUTE_SECOND) from t1;
631
date_add(date,INTERVAL "1:1" MINUTE_SECOND)
632
2003-01-02 00:01:01
633
select date_add(date,INTERVAL "1:1" HOUR_MINUTE) from t1;
634
date_add(date,INTERVAL "1:1" HOUR_MINUTE)
635
2003-01-02 01:01:00
636
select date_add(date,INTERVAL "1:1" DAY_HOUR) from t1;
637
date_add(date,INTERVAL "1:1" DAY_HOUR)
638
2003-01-03 01:00:00
639
select date_add(date,INTERVAL "1 1" YEAR_MONTH) from t1;
640
date_add(date,INTERVAL "1 1" YEAR_MONTH)
641
2004-02-02
642
select date_add(date,INTERVAL "1:1:1" HOUR_SECOND) from t1;
643
date_add(date,INTERVAL "1:1:1" HOUR_SECOND)
644
2003-01-02 01:01:01
645
select date_add(date,INTERVAL "1 1:1" DAY_MINUTE) from t1;
646
date_add(date,INTERVAL "1 1:1" DAY_MINUTE)
647
2003-01-03 01:01:00
648
select date_add(date,INTERVAL "1 1:1:1" DAY_SECOND) from t1;
649
date_add(date,INTERVAL "1 1:1:1" DAY_SECOND)
650
2003-01-03 01:01:01
651
select date_add(date,INTERVAL "1" WEEK) from t1;
652
date_add(date,INTERVAL "1" WEEK)
653
2003-01-09
654
select date_add(date,INTERVAL "1" QUARTER) from t1;
655
date_add(date,INTERVAL "1" QUARTER)
656
2003-04-02
657
select timestampadd(MINUTE, 1, date) from t1;
658
timestampadd(MINUTE, 1, date)
659
2003-01-02 00:01:00
660
select timestampadd(WEEK, 1, date) from t1;
661
timestampadd(WEEK, 1, date)
662
2003-01-09
663
select timestampadd(SQL_TSI_SECOND, 1, date) from t1;
664
timestampadd(SQL_TSI_SECOND, 1, date)
665
2003-01-02 00:00:01
666
select timestampadd(SQL_TSI_FRAC_SECOND, 1, date) from t1;
667
timestampadd(SQL_TSI_FRAC_SECOND, 1, date)
668
2003-01-02 00:00:00.000001
669
Warnings:
670
Warning	1287	The syntax 'FRAC_SECOND' is deprecated and will be removed in MySQL 6.2. Please use MICROSECOND instead
671
select timestampdiff(MONTH, '2001-02-01', '2001-05-01') as a;
672
a
673
3
674
select timestampdiff(YEAR, '2002-05-01', '2001-01-01') as a;
675
a
676
-1
677
select timestampdiff(QUARTER, '2002-05-01', '2001-01-01') as a;
678
a
679
-5
680
select timestampdiff(MONTH, '2000-03-28', '2000-02-29') as a;
681
a
682
0
683
select timestampdiff(MONTH, '1991-03-28', '2000-02-29') as a;
684
a
685
107
686
select timestampdiff(SQL_TSI_WEEK, '2001-02-01', '2001-05-01') as a;
687
a
688
12
689
select timestampdiff(SQL_TSI_HOUR, '2001-02-01', '2001-05-01') as a;
690
a
691
2136
692
select timestampdiff(SQL_TSI_DAY, '2001-02-01', '2001-05-01') as a;
693
a
694
89
695
select timestampdiff(SQL_TSI_MINUTE, '2001-02-01 12:59:59', '2001-05-01 12:58:59') as a;
696
a
697
128159
698
select timestampdiff(SQL_TSI_SECOND, '2001-02-01 12:59:59', '2001-05-01 12:58:58') as a;
699
a
700
7689539
701
select timestampdiff(SQL_TSI_FRAC_SECOND, '2001-02-01 12:59:59.120000', '2001-05-01 12:58:58.119999') as a;
702
a
703
7689538999999
704
Warnings:
705
Warning	1287	The syntax 'FRAC_SECOND' is deprecated and will be removed in MySQL 6.2. Please use MICROSECOND instead
706
select timestampdiff(SQL_TSI_DAY, '1986-02-01', '1986-03-01') as a1,
707
timestampdiff(SQL_TSI_DAY, '1900-02-01', '1900-03-01') as a2,
708
timestampdiff(SQL_TSI_DAY, '1996-02-01', '1996-03-01') as a3,
709
timestampdiff(SQL_TSI_DAY, '2000-02-01', '2000-03-01') as a4;
710
a1	a2	a3	a4
711
28	28	29	29
712
SELECT TIMESTAMPDIFF(day,'2006-01-10 14:30:28','2006-01-11 14:30:27');
713
TIMESTAMPDIFF(day,'2006-01-10 14:30:28','2006-01-11 14:30:27')
714
0
715
SELECT TIMESTAMPDIFF(day,'2006-01-10 14:30:28','2006-01-11 14:30:28');
716
TIMESTAMPDIFF(day,'2006-01-10 14:30:28','2006-01-11 14:30:28')
717
1
718
SELECT TIMESTAMPDIFF(day,'2006-01-10 14:30:28','2006-01-11 14:30:29');
719
TIMESTAMPDIFF(day,'2006-01-10 14:30:28','2006-01-11 14:30:29')
720
1
721
SELECT TIMESTAMPDIFF(day,'2006-01-10 14:30:28','2006-01-12 14:30:27');
722
TIMESTAMPDIFF(day,'2006-01-10 14:30:28','2006-01-12 14:30:27')
723
1
724
SELECT TIMESTAMPDIFF(day,'2006-01-10 14:30:28','2006-01-12 14:30:28');
725
TIMESTAMPDIFF(day,'2006-01-10 14:30:28','2006-01-12 14:30:28')
726
2
727
SELECT TIMESTAMPDIFF(day,'2006-01-10 14:30:28','2006-01-12 14:30:29');
728
TIMESTAMPDIFF(day,'2006-01-10 14:30:28','2006-01-12 14:30:29')
729
2
730
SELECT TIMESTAMPDIFF(week,'2006-01-10 14:30:28','2006-01-17 14:30:27');
731
TIMESTAMPDIFF(week,'2006-01-10 14:30:28','2006-01-17 14:30:27')
732
0
733
SELECT TIMESTAMPDIFF(week,'2006-01-10 14:30:28','2006-01-17 14:30:28');
734
TIMESTAMPDIFF(week,'2006-01-10 14:30:28','2006-01-17 14:30:28')
735
1
736
SELECT TIMESTAMPDIFF(week,'2006-01-10 14:30:28','2006-01-17 14:30:29');
737
TIMESTAMPDIFF(week,'2006-01-10 14:30:28','2006-01-17 14:30:29')
738
1
739
SELECT TIMESTAMPDIFF(week,'2006-01-10 14:30:28','2006-01-24 14:30:27');
740
TIMESTAMPDIFF(week,'2006-01-10 14:30:28','2006-01-24 14:30:27')
741
1
742
SELECT TIMESTAMPDIFF(week,'2006-01-10 14:30:28','2006-01-24 14:30:28');
743
TIMESTAMPDIFF(week,'2006-01-10 14:30:28','2006-01-24 14:30:28')
744
2
745
SELECT TIMESTAMPDIFF(week,'2006-01-10 14:30:28','2006-01-24 14:30:29');
746
TIMESTAMPDIFF(week,'2006-01-10 14:30:28','2006-01-24 14:30:29')
747
2
748
SELECT TIMESTAMPDIFF(month,'2006-01-10 14:30:28','2006-02-10 14:30:27');
749
TIMESTAMPDIFF(month,'2006-01-10 14:30:28','2006-02-10 14:30:27')
750
0
751
SELECT TIMESTAMPDIFF(month,'2006-01-10 14:30:28','2006-02-10 14:30:28');
752
TIMESTAMPDIFF(month,'2006-01-10 14:30:28','2006-02-10 14:30:28')
753
1
754
SELECT TIMESTAMPDIFF(month,'2006-01-10 14:30:28','2006-02-10 14:30:29');
755
TIMESTAMPDIFF(month,'2006-01-10 14:30:28','2006-02-10 14:30:29')
756
1
757
SELECT TIMESTAMPDIFF(month,'2006-01-10 14:30:28','2006-03-10 14:30:27');
758
TIMESTAMPDIFF(month,'2006-01-10 14:30:28','2006-03-10 14:30:27')
759
1
760
SELECT TIMESTAMPDIFF(month,'2006-01-10 14:30:28','2006-03-10 14:30:28');
761
TIMESTAMPDIFF(month,'2006-01-10 14:30:28','2006-03-10 14:30:28')
762
2
763
SELECT TIMESTAMPDIFF(month,'2006-01-10 14:30:28','2006-03-10 14:30:29');
764
TIMESTAMPDIFF(month,'2006-01-10 14:30:28','2006-03-10 14:30:29')
765
2
766
SELECT TIMESTAMPDIFF(year,'2006-01-10 14:30:28','2007-01-10 14:30:27');
767
TIMESTAMPDIFF(year,'2006-01-10 14:30:28','2007-01-10 14:30:27')
768
0
769
SELECT TIMESTAMPDIFF(year,'2006-01-10 14:30:28','2007-01-10 14:30:28');
770
TIMESTAMPDIFF(year,'2006-01-10 14:30:28','2007-01-10 14:30:28')
771
1
772
SELECT TIMESTAMPDIFF(year,'2006-01-10 14:30:28','2007-01-10 14:30:29');
773
TIMESTAMPDIFF(year,'2006-01-10 14:30:28','2007-01-10 14:30:29')
774
1
775
SELECT TIMESTAMPDIFF(year,'2006-01-10 14:30:28','2008-01-10 14:30:27');
776
TIMESTAMPDIFF(year,'2006-01-10 14:30:28','2008-01-10 14:30:27')
777
1
778
SELECT TIMESTAMPDIFF(year,'2006-01-10 14:30:28','2008-01-10 14:30:28');
779
TIMESTAMPDIFF(year,'2006-01-10 14:30:28','2008-01-10 14:30:28')
780
2
781
SELECT TIMESTAMPDIFF(year,'2006-01-10 14:30:28','2008-01-10 14:30:29');
782
TIMESTAMPDIFF(year,'2006-01-10 14:30:28','2008-01-10 14:30:29')
783
2
784
select date_add(time,INTERVAL 1 SECOND) from t1;
785
date_add(time,INTERVAL 1 SECOND)
786
NULL
787
Warnings:
788
Warning	1264	Out of range value for column 'time' at row 1
789
drop table t1;
790
select last_day('2000-02-05') as f1, last_day('2002-12-31') as f2,
791
last_day('2003-03-32') as f3, last_day('2003-04-01') as f4,
792
last_day('2001-01-01 01:01:01') as f5, last_day(NULL),
793
last_day('2001-02-12');
794
f1	f2	f3	f4	f5	last_day(NULL)	last_day('2001-02-12')
795
2000-02-29	2002-12-31	NULL	2003-04-30	2001-01-31	NULL	2001-02-28
796
Warnings:
797
Warning	1292	Incorrect datetime value: '2003-03-32'
798
create table t1 select last_day('2000-02-05') as a,
799
from_days(to_days("960101")) as b;
800
describe t1;
801
Field	Type	Null	Key	Default	Extra
802
a	date	NO		0000-00-00	
803
b	date	YES		NULL	
804
select * from t1;
805
a	b
806
2000-02-29	1996-01-01
807
drop table t1;
808
select last_day('2000-02-05') as a,
809
from_days(to_days("960101")) as b;
810
a	b
811
2000-02-29	1996-01-01
812
select date_add(last_day("1997-12-1"), INTERVAL 1 DAY);
813
date_add(last_day("1997-12-1"), INTERVAL 1 DAY)
814
1998-01-01
815
select length(last_day("1997-12-1"));
816
length(last_day("1997-12-1"))
817
10
818
select last_day("1997-12-1")+0;
819
last_day("1997-12-1")+0
820
19971231
821
select last_day("1997-12-1")+0.0;
822
last_day("1997-12-1")+0.0
823
19971231.0
824
select strcmp(date_sub(localtimestamp(), interval 3 hour), utc_timestamp())=0;
825
strcmp(date_sub(localtimestamp(), interval 3 hour), utc_timestamp())=0
826
1
827
select strcmp(date_format(date_sub(localtimestamp(), interval 3 hour),"%T"), utc_time())=0;
828
strcmp(date_format(date_sub(localtimestamp(), interval 3 hour),"%T"), utc_time())=0
829
1
830
select strcmp(date_format(date_sub(localtimestamp(), interval 3 hour),"%Y-%m-%d"), utc_date())=0;
831
strcmp(date_format(date_sub(localtimestamp(), interval 3 hour),"%Y-%m-%d"), utc_date())=0
832
1
833
select strcmp(date_format(utc_timestamp(),"%T"), utc_time())=0;
834
strcmp(date_format(utc_timestamp(),"%T"), utc_time())=0
835
1
836
select strcmp(date_format(utc_timestamp(),"%Y-%m-%d"), utc_date())=0;
837
strcmp(date_format(utc_timestamp(),"%Y-%m-%d"), utc_date())=0
838
1
839
select strcmp(concat(utc_date(),' ',utc_time()),utc_timestamp())=0;
840
strcmp(concat(utc_date(),' ',utc_time()),utc_timestamp())=0
841
1
842
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);
843
id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
844
1	SIMPLE	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	No tables used
845
Warnings:
846
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',0) 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)`
847
SET @TMP='2007-08-01 12:22:49';
848
CREATE TABLE t1 (d DATETIME);
849
INSERT INTO t1 VALUES ('2007-08-01 12:22:59');
850
INSERT INTO t1 VALUES ('2007-08-01 12:23:01');
851
INSERT INTO t1 VALUES ('2007-08-01 12:23:20');
852
SELECT count(*) FROM t1 WHERE d>FROM_DAYS(TO_DAYS(@TMP)) AND d<=FROM_DAYS(TO_DAYS(@TMP)+1);
853
count(*)
854
3
855
DROP TABLE t1;
856
select last_day('2005-00-00');
857
last_day('2005-00-00')
858
NULL
859
Warnings:
860
Warning	1292	Incorrect datetime value: '2005-00-00'
861
select last_day('2005-00-01');
862
last_day('2005-00-01')
863
NULL
864
Warnings:
865
Warning	1292	Incorrect datetime value: '2005-00-01'
866
select last_day('2005-01-00');
867
last_day('2005-01-00')
868
NULL
869
Warnings:
870
Warning	1292	Incorrect datetime value: '2005-01-00'
871
select monthname(str_to_date(null, '%m')), monthname(str_to_date(null, '%m')),
872
monthname(str_to_date(1, '%m')), monthname(str_to_date(0, '%m'));
873
monthname(str_to_date(null, '%m'))	monthname(str_to_date(null, '%m'))	monthname(str_to_date(1, '%m'))	monthname(str_to_date(0, '%m'))
874
NULL	NULL	January	NULL
875
set time_zone='-6:00';
876
create table t1(a timestamp);
877
insert into t1 values (19691231190001);
878
select * from t1;
879
a
880
1969-12-31 19:00:01
881
drop table t1;
882
create table t1(f1 date, f2 time, f3 datetime);
883
insert into t1 values ("2006-01-01", "12:01:01", "2006-01-01 12:01:01");
884
insert into t1 values ("2006-01-02", "12:01:02", "2006-01-02 12:01:02");
885
select f1 from t1 where f1 between CAST("2006-1-1" as date) and CAST(20060101 as date);
886
f1
887
2006-01-01
888
select f1 from t1 where f1 between cast("2006-1-1" as date) and cast("2006.1.1" as date);
889
f1
890
2006-01-01
891
select f1 from t1 where date(f1) between cast("2006-1-1" as date) and cast("2006.1.1" as date);
892
f1
893
2006-01-01
894
select f2 from t1 where f2 between cast("12:1:2" as time) and cast("12:2:2" as time);
895
f2
896
12:01:02
897
select f2 from t1 where time(f2) between cast("12:1:2" as time) and cast("12:2:2" as time);
898
f2
899
12:01:02
900
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);
901
f3
902
2006-01-01 12:01:01
903
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);
904
f3
905
2006-01-01 12:01:01
906
select f1 from t1 where cast("2006-1-1" as date) between f1 and f3;
907
f1
908
2006-01-01
909
select f1 from t1 where cast("2006-1-1" as date) between date(f1) and date(f3);
910
f1
911
2006-01-01
912
select f1 from t1 where cast("2006-1-1" as date) between f1 and cast('zzz' as date);
913
f1
914
Warnings:
915
Warning	1292	Incorrect datetime value: 'zzz'
916
Warning	1292	Incorrect datetime value: 'zzz'
917
select f1 from t1 where makedate(2006,1) between date(f1) and date(f3);
918
f1
919
2006-01-01
920
select f1 from t1 where makedate(2006,2) between date(f1) and date(f3);
921
f1
922
2006-01-02
923
drop table t1;
924
create table t1 select now() - now(), curtime() - curtime(), 
925
sec_to_time(1) + 0, from_unixtime(1) + 0;
926
show create table t1;
927
Table	Create Table
928
t1	CREATE TABLE `t1` (
929
  `now() - now()` double(23,6) NOT NULL DEFAULT '0.000000',
930
  `curtime() - curtime()` double(23,6) NOT NULL DEFAULT '0.000000',
931
  `sec_to_time(1) + 0` double(23,6) DEFAULT NULL,
932
  `from_unixtime(1) + 0` double(23,6) DEFAULT NULL
933
) ENGINE=MyISAM DEFAULT CHARSET=latin1
934
drop table t1;
935
SELECT SEC_TO_TIME(3300000);
936
SEC_TO_TIME(3300000)
937
838:59:59
938
Warnings:
939
Warning	1292	Truncated incorrect time value: '3300000'
940
SELECT SEC_TO_TIME(3300000)+0;
941
SEC_TO_TIME(3300000)+0
942
8385959.000000
943
Warnings:
944
Warning	1292	Truncated incorrect time value: '3300000'
945
SELECT SEC_TO_TIME(3600 * 4294967296);
946
SEC_TO_TIME(3600 * 4294967296)
947
838:59:59
948
Warnings:
949
Warning	1292	Truncated incorrect time value: '15461882265600'
950
SELECT TIME_TO_SEC('916:40:00');
951
TIME_TO_SEC('916:40:00')
952
3020399
953
Warnings:
954
Warning	1292	Truncated incorrect time value: '916:40:00'
955
SELECT ADDTIME('500:00:00', '416:40:00');
956
ADDTIME('500:00:00', '416:40:00')
957
838:59:59
958
Warnings:
959
Warning	1292	Truncated incorrect time value: '916:40:00'
960
SELECT ADDTIME('916:40:00', '416:40:00');
961
ADDTIME('916:40:00', '416:40:00')
962
838:59:59
963
Warnings:
964
Warning	1292	Truncated incorrect time value: '916:40:00'
965
Warning	1292	Truncated incorrect time value: '1255:39:59'
966
SELECT SUBTIME('916:40:00', '416:40:00');
967
SUBTIME('916:40:00', '416:40:00')
968
422:19:59
969
Warnings:
970
Warning	1292	Truncated incorrect time value: '916:40:00'
971
SELECT SUBTIME('-916:40:00', '416:40:00');
972
SUBTIME('-916:40:00', '416:40:00')
973
-838:59:59
974
Warnings:
975
Warning	1292	Truncated incorrect time value: '-916:40:00'
976
Warning	1292	Truncated incorrect time value: '-1255:39:59'
977
SELECT MAKETIME(916,0,0);
978
MAKETIME(916,0,0)
979
838:59:59
980
Warnings:
981
Warning	1292	Truncated incorrect time value: '916:00:00'
982
SELECT MAKETIME(4294967296, 0, 0);
983
MAKETIME(4294967296, 0, 0)
984
838:59:59
985
Warnings:
986
Warning	1292	Truncated incorrect time value: '4294967296:00:00'
987
SELECT MAKETIME(-4294967296, 0, 0);
988
MAKETIME(-4294967296, 0, 0)
989
-838:59:59
990
Warnings:
991
Warning	1292	Truncated incorrect time value: '-4294967296:00:00'
992
SELECT MAKETIME(0, 4294967296, 0);
993
MAKETIME(0, 4294967296, 0)
994
NULL
995
SELECT MAKETIME(0, 0, 4294967296);
996
MAKETIME(0, 0, 4294967296)
997
NULL
998
SELECT MAKETIME(CAST(-1 AS UNSIGNED), 0, 0);
999
MAKETIME(CAST(-1 AS UNSIGNED), 0, 0)
1000
838:59:59
1001
Warnings:
1002
Warning	1292	Truncated incorrect time value: '18446744073709551615:00:00'
1003
SELECT EXTRACT(HOUR FROM '100000:02:03');
1004
EXTRACT(HOUR FROM '100000:02:03')
1005
838
1006
Warnings:
1007
Warning	1292	Truncated incorrect time value: '100000:02:03'
1008
CREATE TABLE t1(f1 TIME);
1009
INSERT INTO t1 VALUES('916:00:00 a');
1010
Warnings:
1011
Warning	1265	Data truncated for column 'f1' at row 1
1012
Warning	1264	Out of range value for column 'f1' at row 1
1013
SELECT * FROM t1;
1014
f1
1015
838:59:59
1016
DROP TABLE t1;
1017
SELECT SEC_TO_TIME(CAST(-1 AS UNSIGNED));
1018
SEC_TO_TIME(CAST(-1 AS UNSIGNED))
1019
838:59:59
1020
Warnings:
1021
Warning	1292	Truncated incorrect time value: '18446744073709551615'
1022
SET NAMES latin1;
1023
SET character_set_results = NULL;
1024
SHOW VARIABLES LIKE 'character_set_results';
1025
Variable_name	Value
1026
character_set_results	
1027
CREATE TABLE testBug8868 (field1 DATE, field2 VARCHAR(32) CHARACTER SET BINARY);
1028
INSERT INTO testBug8868 VALUES ('2006-09-04', 'abcd');
1029
SELECT DATE_FORMAT(field1,'%b-%e %l:%i%p') as fmtddate, field2 FROM testBug8868;
1030
fmtddate	field2
1031
Sep-4 12:00AM	abcd
1032
DROP TABLE testBug8868;
1033
SET NAMES DEFAULT;
1034
CREATE TABLE t1 (
1035
a TIMESTAMP
1036
);
1037
INSERT INTO t1 VALUES (now()), (now());
1038
SELECT 1 FROM t1 ORDER BY MAKETIME(1, 1, a);
1039
1
1040
1
1041
1
1042
DROP TABLE t1;
1043
(select time_format(timediff(now(), DATE_SUB(now(),INTERVAL 5 DAY)),'%H') As H)
1044
union
1045
(select time_format(timediff(now(), DATE_SUB(now(),INTERVAL 5 DAY)),'%H') As H);
1046
H
1047
120
1048
(select time_format(timediff(now(), DATE_SUB(now(),INTERVAL 5 DAY)),'%k') As H)
1049
union
1050
(select time_format(timediff(now(), DATE_SUB(now(),INTERVAL 5 DAY)),'%k') As H);
1051
H
1052
120
1053
(select time_format(timediff(now(), DATE_SUB(now(),INTERVAL 5 HOUR)),'%H') As H)
1054
union
1055
(select time_format(timediff(now(), DATE_SUB(now(),INTERVAL 5 HOUR)),'%H') As H);
1056
H
1057
05
1058
(select time_format(timediff(now(), DATE_SUB(now(),INTERVAL 5 HOUR)),'%k') As H)
1059
union
1060
(select time_format(timediff(now(), DATE_SUB(now(),INTERVAL 5 HOUR)),'%k') As H);
1061
H
1062
5
1063
select last_day('0000-00-00');
1064
last_day('0000-00-00')
1065
NULL
1066
select isnull(week(now() + 0)), isnull(week(now() + 0.2)),
1067
week(20061108), week(20061108.01), week(20061108085411.000002);
1068
isnull(week(now() + 0))	isnull(week(now() + 0.2))	week(20061108)	week(20061108.01)	week(20061108085411.000002)
1069
0	0	45	45	45
1070
End of 4.1 tests
1071
explain extended select timestampdiff(SQL_TSI_WEEK, '2001-02-01', '2001-05-01') as a1,
1072
timestampdiff(SQL_TSI_FRAC_SECOND, '2001-02-01 12:59:59.120000', '2001-05-01 12:58:58.119999') as a2;
1073
id	select_type	table	type	possible_keys	key	key_len	ref	rows	filtered	Extra
1074
1	SIMPLE	NULL	NULL	NULL	NULL	NULL	NULL	NULL	NULL	No tables used
1075
Warnings:
1076
Warning	1287	The syntax 'FRAC_SECOND' is deprecated and will be removed in MySQL 6.2. Please use MICROSECOND instead
1077
Note	1003	select timestampdiff(WEEK,'2001-02-01','2001-05-01') AS `a1`,timestampdiff(SECOND_FRAC,'2001-02-01 12:59:59.120000','2001-05-01 12:58:58.119999') AS `a2`
1078
select time_format('100:00:00', '%H %k %h %I %l');
1079
time_format('100:00:00', '%H %k %h %I %l')
1080
100 100 04 04 4
1081
SET GLOBAL log_bin_trust_function_creators = 1;
1082
create table t1 (a timestamp default '2005-05-05 01:01:01',
1083
b timestamp default '2005-05-05 01:01:01');
1084
drop function if exists t_slow_sysdate;
1085
create function t_slow_sysdate() returns timestamp
1086
begin
1087
do sleep(2);
1088
return sysdate();
1089
end;
1090
//
1091
insert into t1 set a = sysdate(), b = t_slow_sysdate();//
1092
create trigger t_before before insert on t1
1093
for each row begin
1094
set new.b = t_slow_sysdate();
1095
end
1096
//
1097
insert into t1 set a = sysdate();
1098
select a != b from t1;
1099
a != b
1100
1
1101
1
1102
drop trigger t_before;
1103
drop function t_slow_sysdate;
1104
drop table t1;
1105
SET GLOBAL log_bin_trust_function_creators = 0;
1106
create table t1 (a datetime, i int, b datetime);
1107
insert into t1 select sysdate(), sleep(1), sysdate() from dual;
1108
select a != b from t1;
1109
a != b
1110
1
1111
drop table t1;
1112
create procedure t_sysdate()
1113
begin
1114
select sysdate() into @a;
1115
do sleep(2);
1116
select sysdate() into @b;
1117
select @a != @b;
1118
end;
1119
//
1120
call t_sysdate();
1121
@a != @b
1122
1
1123
drop procedure t_sysdate;
1124
select timestampdiff(month,'2004-09-11','2004-09-11');
1125
timestampdiff(month,'2004-09-11','2004-09-11')
1126
0
1127
select timestampdiff(month,'2004-09-11','2005-09-11');
1128
timestampdiff(month,'2004-09-11','2005-09-11')
1129
12
1130
select timestampdiff(month,'2004-09-11','2006-09-11');
1131
timestampdiff(month,'2004-09-11','2006-09-11')
1132
24
1133
select timestampdiff(month,'2004-09-11','2007-09-11');
1134
timestampdiff(month,'2004-09-11','2007-09-11')
1135
36
1136
select timestampdiff(month,'2005-09-11','2004-09-11');
1137
timestampdiff(month,'2005-09-11','2004-09-11')
1138
-12
1139
select timestampdiff(month,'2005-09-11','2003-09-11');
1140
timestampdiff(month,'2005-09-11','2003-09-11')
1141
-24
1142
select timestampdiff(month,'2004-02-28','2005-02-28');
1143
timestampdiff(month,'2004-02-28','2005-02-28')
1144
12
1145
select timestampdiff(month,'2004-02-29','2005-02-28');
1146
timestampdiff(month,'2004-02-29','2005-02-28')
1147
11
1148
select timestampdiff(month,'2004-02-28','2005-02-28');
1149
timestampdiff(month,'2004-02-28','2005-02-28')
1150
12
1151
select timestampdiff(month,'2004-03-29','2005-03-28');
1152
timestampdiff(month,'2004-03-29','2005-03-28')
1153
11
1154
select timestampdiff(month,'2003-02-28','2004-02-29');
1155
timestampdiff(month,'2003-02-28','2004-02-29')
1156
12
1157
select timestampdiff(month,'2003-02-28','2005-02-28');
1158
timestampdiff(month,'2003-02-28','2005-02-28')
1159
24
1160
select timestampdiff(month,'1999-09-11','2001-10-10');
1161
timestampdiff(month,'1999-09-11','2001-10-10')
1162
24
1163
select timestampdiff(month,'1999-09-11','2001-9-11');
1164
timestampdiff(month,'1999-09-11','2001-9-11')
1165
24
1166
select timestampdiff(year,'1999-09-11','2001-9-11');
1167
timestampdiff(year,'1999-09-11','2001-9-11')
1168
2
1169
select timestampdiff(year,'2004-02-28','2005-02-28');
1170
timestampdiff(year,'2004-02-28','2005-02-28')
1171
1
1172
select timestampdiff(year,'2004-02-29','2005-02-28');
1173
timestampdiff(year,'2004-02-29','2005-02-28')
1174
0
1175
CREATE TABLE t1 (id int NOT NULL PRIMARY KEY, day date);
1176
CREATE TABLE t2 (id int NOT NULL PRIMARY KEY, day date);
1177
INSERT INTO t1 VALUES
1178
(1, '2005-06-01'), (2, '2005-02-01'), (3, '2005-07-01');
1179
INSERT INTO t2 VALUES
1180
(1, '2005-08-01'), (2, '2005-06-15'), (3, '2005-07-15');
1181
SELECT * FROM t1, t2 
1182
WHERE t1.day BETWEEN 
1183
'2005.09.01' - INTERVAL 6 MONTH AND t2.day;
1184
id	day	id	day
1185
1	2005-06-01	1	2005-08-01
1186
3	2005-07-01	1	2005-08-01
1187
1	2005-06-01	2	2005-06-15
1188
1	2005-06-01	3	2005-07-15
1189
3	2005-07-01	3	2005-07-15
1190
SELECT * FROM t1, t2 
1191
WHERE CAST(t1.day AS DATE) BETWEEN 
1192
'2005.09.01' - INTERVAL 6 MONTH AND t2.day;
1193
id	day	id	day
1194
1	2005-06-01	1	2005-08-01
1195
3	2005-07-01	1	2005-08-01
1196
1	2005-06-01	2	2005-06-15
1197
1	2005-06-01	3	2005-07-15
1198
3	2005-07-01	3	2005-07-15
1199
DROP TABLE t1,t2;
1200
set time_zone= @@global.time_zone;
1201
select str_to_date('10:00 PM', '%h:%i %p') + INTERVAL 10 MINUTE;
1202
str_to_date('10:00 PM', '%h:%i %p') + INTERVAL 10 MINUTE
1203
NULL
1204
create table t1 (field DATE);
1205
insert into t1 values ('2006-11-06');
1206
select * from t1 where field < '2006-11-06 04:08:36.0';
1207
field
1208
2006-11-06
1209
select * from t1 where field = '2006-11-06 04:08:36.0';
1210
field
1211
select * from t1 where field = '2006-11-06';
1212
field
1213
2006-11-06
1214
select * from t1 where CAST(field as DATETIME) < '2006-11-06 04:08:36.0';
1215
field
1216
2006-11-06
1217
select * from t1 where CAST(field as DATE) < '2006-11-06 04:08:36.0';
1218
field
1219
2006-11-06
1220
drop table t1;
1221
CREATE TABLE t1 (a int, t1 time, t2 time, d date, PRIMARY KEY  (a));
1222
INSERT INTO t1 VALUES (1, '10:00:00', NULL, NULL), 
1223
(2, '11:00:00', '11:15:00', '1972-02-06');
1224
SELECT t1, t2, SEC_TO_TIME( TIME_TO_SEC( t2 ) - TIME_TO_SEC( t1 ) ), QUARTER(d) 
1225
FROM t1;
1226
t1	t2	SEC_TO_TIME( TIME_TO_SEC( t2 ) - TIME_TO_SEC( t1 ) )	QUARTER(d)
1227
10:00:00	NULL	NULL	NULL
1228
11:00:00	11:15:00	00:15:00	1
1229
SELECT t1, t2, SEC_TO_TIME( TIME_TO_SEC( t2 ) - TIME_TO_SEC( t1 ) ), QUARTER(d)
1230
FROM t1 ORDER BY a DESC;
1231
t1	t2	SEC_TO_TIME( TIME_TO_SEC( t2 ) - TIME_TO_SEC( t1 ) )	QUARTER(d)
1232
11:00:00	11:15:00	00:15:00	1
1233
10:00:00	NULL	NULL	NULL
1234
DROP TABLE t1;
1235
SELECT TIME_FORMAT(SEC_TO_TIME(a),"%H:%i:%s") FROM (SELECT 3020399 AS a UNION SELECT 3020398 ) x GROUP BY 1;
1236
TIME_FORMAT(SEC_TO_TIME(a),"%H:%i:%s")
1237
838:59:58
1238
838:59:59
1239
set names latin1;
1240
create table t1 (a varchar(15) character set ascii not null);
1241
insert into t1 values ('070514-000000');
1242
select concat(a,ifnull(min(date_format(now(), '%Y-%m-%d')),' ull')) from t1;
1243
concat(a,ifnull(min(date_format(now(), '%Y-%m-%d')),' ull'))
1244
#
1245
set names swe7;
1246
select concat(a,ifnull(min(date_format(now(), '%Y-%m-%d')),' ull')) from t1;
1247
ERROR HY000: Illegal mix of collations (ascii_general_ci,IMPLICIT) and (swe7_swedish_ci,COERCIBLE) for operation 'concat'
1248
set names latin1;
1249
set lc_time_names=fr_FR;
1250
select concat(a,ifnull(min(date_format(now(), '%Y-%m-%d')),' ull')) from t1;
1251
ERROR HY000: Illegal mix of collations (ascii_general_ci,IMPLICIT) and (latin1_swedish_ci,COERCIBLE) for operation 'concat'
1252
set lc_time_names=en_US;
1253
drop table t1;
1254
select DATE_ADD('20071108181000', INTERVAL 1 DAY);
1255
DATE_ADD('20071108181000', INTERVAL 1 DAY)
1256
2007-11-09 18:10:00
1257
select DATE_ADD(20071108181000,   INTERVAL 1 DAY);
1258
DATE_ADD(20071108181000,   INTERVAL 1 DAY)
1259
2007-11-09 18:10:00
1260
select DATE_ADD('20071108',       INTERVAL 1 DAY);
1261
DATE_ADD('20071108',       INTERVAL 1 DAY)
1262
2007-11-09
1263
select DATE_ADD(20071108,         INTERVAL 1 DAY);
1264
DATE_ADD(20071108,         INTERVAL 1 DAY)
1265
2007-11-09
1266
select LAST_DAY('2007-12-06 08:59:19.05') - INTERVAL 1 SECOND;
1267
LAST_DAY('2007-12-06 08:59:19.05') - INTERVAL 1 SECOND
1268
2007-12-30 23:59:59
1269
SELECT TIMESTAMPADD(FRAC_SECOND, 1, '2008-02-18');
1270
TIMESTAMPADD(FRAC_SECOND, 1, '2008-02-18')
1271
2008-02-18 00:00:00.000001
1272
Warnings:
1273
Warning	1287	The syntax 'FRAC_SECOND' is deprecated and will be removed in MySQL 6.2. Please use MICROSECOND instead
1274
SELECT TIMESTAMPDIFF(FRAC_SECOND, '2008-02-17', '2008-02-18');
1275
TIMESTAMPDIFF(FRAC_SECOND, '2008-02-17', '2008-02-18')
1276
86400000000
1277
Warnings:
1278
Warning	1287	The syntax 'FRAC_SECOND' is deprecated and will be removed in MySQL 6.2. Please use MICROSECOND instead
1279
SELECT DATE_ADD('2008-02-18', INTERVAL 1 FRAC_SECOND);
1280
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'FRAC_SECOND)' at line 1
1281
SELECT DATE_SUB('2008-02-18', INTERVAL 1 FRAC_SECOND);
1282
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'FRAC_SECOND)' at line 1
1283
SELECT '2008-02-18' + INTERVAL 1 FRAC_SECOND;
1284
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'FRAC_SECOND' at line 1
1285
SELECT '2008-02-18' - INTERVAL 1 FRAC_SECOND;
1286
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'FRAC_SECOND' at line 1
1287
End of 5.0 tests
1288
select date_sub("0050-01-01 00:00:01",INTERVAL 2 SECOND);
1289
date_sub("0050-01-01 00:00:01",INTERVAL 2 SECOND)
1290
0049-12-31 23:59:59
1291
select date_sub("0199-01-01 00:00:01",INTERVAL 2 SECOND);
1292
date_sub("0199-01-01 00:00:01",INTERVAL 2 SECOND)
1293
0198-12-31 23:59:59
1294
select date_add("0199-12-31 23:59:59",INTERVAL 2 SECOND);
1295
date_add("0199-12-31 23:59:59",INTERVAL 2 SECOND)
1296
0200-01-01 00:00:01
1297
select date_sub("0200-01-01 00:00:01",INTERVAL 2 SECOND);
1298
date_sub("0200-01-01 00:00:01",INTERVAL 2 SECOND)
1299
0199-12-31 23:59:59
1300
select date_sub("0200-01-01 00:00:01",INTERVAL 1 SECOND);
1301
date_sub("0200-01-01 00:00:01",INTERVAL 1 SECOND)
1302
0200-01-01 00:00:00
1303
select date_sub("0200-01-01 00:00:01",INTERVAL 2 SECOND);
1304
date_sub("0200-01-01 00:00:01",INTERVAL 2 SECOND)
1305
0199-12-31 23:59:59
1306
select date_add("2001-01-01 23:59:59",INTERVAL -2000 YEAR);
1307
date_add("2001-01-01 23:59:59",INTERVAL -2000 YEAR)
1308
0001-01-01 23:59:59
1309
select date_sub("50-01-01 00:00:01",INTERVAL 2 SECOND);
1310
date_sub("50-01-01 00:00:01",INTERVAL 2 SECOND)
1311
2049-12-31 23:59:59
1312
select date_sub("90-01-01 00:00:01",INTERVAL 2 SECOND);
1313
date_sub("90-01-01 00:00:01",INTERVAL 2 SECOND)
1314
1989-12-31 23:59:59
1315
select date_sub("0069-01-01 00:00:01",INTERVAL 2 SECOND);
1316
date_sub("0069-01-01 00:00:01",INTERVAL 2 SECOND)
1317
0068-12-31 23:59:59
1318
select date_sub("0169-01-01 00:00:01",INTERVAL 2 SECOND);
1319
date_sub("0169-01-01 00:00:01",INTERVAL 2 SECOND)
1320
0168-12-31 23:59:59
1321
End of 5.1 tests