~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to tests/r/date_formats.result

  • Committer: Brian Aker
  • Date: 2008-09-05 22:16:26 UTC
  • mto: This revision was merged to the branch mainline in revision 383.
  • Revision ID: brian@tangent.org-20080905221626-nc631ypag04am60c
Big, fat, UTF-8 patch. This fixes some of the oddities around only one
charset.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
drop table if exists t1;
2
 
SHOW GLOBAL VARIABLES LIKE "%e_format";
3
 
Variable_name   Value
4
 
date_format     %d.%m.%Y
5
 
datetime_format %Y-%m-%d %H:%i:%s
6
 
innodb_file_format      Antelope
7
 
time_format     %H.%i.%s
8
 
SHOW SESSION VARIABLES LIKE "%e_format";
9
 
Variable_name   Value
10
 
date_format     %d.%m.%Y
11
 
datetime_format %Y-%m-%d %H:%i:%s
12
 
innodb_file_format      Antelope
13
 
time_format     %H.%i.%s
14
 
SET time_format='%H%i%s';
15
 
SET time_format='%H:%i:%s.%f';
16
 
SET time_format='%h-%i-%s.%f%p';
17
 
SET time_format='%h:%i:%s.%f %p';
18
 
SET time_format='%h:%i:%s%p';
19
 
SET date_format='%Y%m%d';
20
 
SET date_format='%Y.%m.%d';
21
 
SET date_format='%d.%m.%Y';
22
 
SET date_format='%m-%d-%Y';
23
 
set datetime_format= '%Y%m%d%H%i%s';
24
 
set datetime_format= '%Y-%m-%d %H:%i:%s';
25
 
set datetime_format= '%m-%d-%y %H:%i:%s.%f';
26
 
set datetime_format= '%d-%m-%Y %h:%i:%s%p';
27
 
set datetime_format= '%H:%i:%s %Y-%m-%d';
28
 
set datetime_format= '%H:%i:%s.%f %m-%d-%Y';
29
 
set datetime_format= '%h:%i:%s %p %Y-%m-%d';
30
 
set datetime_format= '%h:%i:%s.%f %p %Y-%m-%d';
31
 
SHOW SESSION VARIABLES LIKE "%e_format";
32
 
Variable_name   Value
33
 
date_format     %m-%d-%Y
34
 
datetime_format %h:%i:%s.%f %p %Y-%m-%d
35
 
innodb_file_format      Antelope
36
 
time_format     %h:%i:%s%p
37
 
SET time_format='%h:%i:%s';
38
 
ERROR 42000: Variable 'time_format' can't be set to the value of '%h:%i:%s'
39
 
SET time_format='%H %i:%s';
40
 
ERROR 42000: Variable 'time_format' can't be set to the value of '%H %i:%s'
41
 
SET time_format='%H::%i:%s';
42
 
ERROR 42000: Variable 'time_format' can't be set to the value of '%H::%i:%s'
43
 
SET time_format='%H:%i:%s%f';
44
 
ERROR 42000: Variable 'time_format' can't be set to the value of '%H:%i:%s%f'
45
 
SET time_format='%H:%i.%f:%s';
46
 
ERROR 42000: Variable 'time_format' can't be set to the value of '%H:%i.%f:%s'
47
 
SET time_format='%H:%i:%s%p';
48
 
ERROR 42000: Variable 'time_format' can't be set to the value of '%H:%i:%s%p'
49
 
SET time_format='%h:%i:%s.%f %p %Y-%m-%d';
50
 
ERROR 42000: Variable 'time_format' can't be set to the value of '%h:%i:%s.%f %p %Y-%m-%d'
51
 
SET time_format='%H%i%s.%f';
52
 
ERROR 42000: Variable 'time_format' can't be set to the value of '%H%i%s.%f'
53
 
SET time_format='%H:%i-%s.%f';
54
 
ERROR 42000: Variable 'time_format' can't be set to the value of '%H:%i-%s.%f'
55
 
SET date_format='%d.%m.%d';
56
 
ERROR 42000: Variable 'date_format' can't be set to the value of '%d.%m.%d'
57
 
SET datetime_format='%h.%m.%y %d.%i.%s';
58
 
ERROR 42000: Variable 'datetime_format' can't be set to the value of '%h.%m.%y %d.%i.%s'
59
 
set datetime_format= '%H:%i:%s.%f %p %Y-%m-%d';
60
 
ERROR 42000: Variable 'datetime_format' can't be set to the value of '%H:%i:%s.%f %p %Y-%m-%d'
61
 
set GLOBAL datetime_format= '%H:%i:%s %Y-%m-%d';
62
 
SET SESSION datetime_format=default;
63
 
select @@global.datetime_format, @@session.datetime_format;
64
 
@@global.datetime_format        @@session.datetime_format
65
 
%H:%i:%s %Y-%m-%d       %H:%i:%s %Y-%m-%d
66
 
SET GLOBAL datetime_format=default;
67
 
SET SESSION datetime_format=default;
68
 
select @@global.datetime_format, @@session.datetime_format;
69
 
@@global.datetime_format        @@session.datetime_format
70
 
%Y-%m-%d %H:%i:%s       %Y-%m-%d %H:%i:%s
71
 
SET GLOBAL date_format=default;
72
 
SET GLOBAL time_format=default;
73
 
SET GLOBAL datetime_format=default;
74
 
SET time_format=default;
75
 
SET date_format=default;
76
 
SET datetime_format=default;
77
 
select str_to_date(concat('15-01-2001',' 2:59:58.999'),
78
 
concat('%d-%m-%Y',' ','%H:%i:%s.%f'));
79
 
str_to_date(concat('15-01-2001',' 2:59:58.999'),
80
 
concat('%d-%m-%Y',' ','%H:%i:%s.%f'))
81
 
2001-01-15 02:59:58.999000
82
 
select STR_TO_DATE('2004.12.12 22.30.61','%Y.%m.%d %T');
83
 
STR_TO_DATE('2004.12.12 22.30.61','%Y.%m.%d %T')
84
 
NULL
85
 
Warnings:
86
 
Error   1411    Incorrect time value: '22.30.61' for function str_to_date
87
 
create table t1 (date char(30), format char(30) not null);
88
 
insert into t1 values
89
 
('2003-01-02 10:11:12', '%Y-%m-%d %H:%i:%S'),
90
 
('03-01-02 8:11:2.123456', '%y-%m-%d %H:%i:%S.%#'),
91
 
('0003-01-02 8:11:2.123456', '%Y-%m-%d %H:%i:%S.%#'),
92
 
('03-01-02 8:11:2.123456',   '%Y-%m-%d %H:%i:%S.%#'),
93
 
('2003-01-02 10:11:12 PM', '%Y-%m-%d %h:%i:%S %p'),
94
 
('2003-01-02 01:11:12.12345AM', '%Y-%m-%d %h:%i:%S.%f%p'),
95
 
('2003-01-02 02:11:12.12345AM', '%Y-%m-%d %h:%i:%S.%f %p'),
96
 
('2003-01-02 12:11:12.12345 am', '%Y-%m-%d %h:%i:%S.%f%p'),
97
 
('2003-01-02 11:11:12Pm', '%Y-%m-%d %h:%i:%S%p'),
98
 
('10:20:10', '%H:%i:%s'),
99
 
('10:20:10', '%h:%i:%s.%f'),
100
 
('10:20:10', '%T'),
101
 
('10:20:10AM', '%h:%i:%s%p'),
102
 
('10:20:10AM', '%r'),
103
 
('10:20:10.44AM', '%h:%i:%s.%f%p'),
104
 
('15-01-2001 12:59:58', '%d-%m-%Y %H:%i:%S'),
105
 
('15 September 2001', '%d %M %Y'),
106
 
('15 SEPTEMB 2001', '%d %M %Y'),
107
 
('15 MAY 2001', '%d %b %Y'),
108
 
('15th May 2001', '%D %b %Y'),
109
 
('Sunday 15 MAY 2001', '%W %d %b %Y'),
110
 
('Sund 15 MAY 2001', '%W %d %b %Y'),
111
 
('Tuesday 00 2002', '%W %U %Y'),
112
 
('Thursday 53 1998', '%W %u %Y'),
113
 
('Sunday 01 2001', '%W %v %x'),
114
 
('Tuesday 52 2001', '%W %V %X'),
115
 
('060 2004', '%j %Y'),
116
 
('4 53 1998', '%w %u %Y'),
117
 
('15-01-2001', '%d-%m-%Y %H:%i:%S'),
118
 
('15-01-20', '%d-%m-%y'),
119
 
('15-2001-1', '%d-%Y-%c');
120
 
select date,format,str_to_date(date, format) as str_to_date from t1;
121
 
date    format  str_to_date
122
 
2003-01-02 10:11:12     %Y-%m-%d %H:%i:%S       2003-01-02 10:11:12
123
 
03-01-02 8:11:2.123456  %y-%m-%d %H:%i:%S.%#    2003-01-02 08:11:02
124
 
0003-01-02 8:11:2.123456        %Y-%m-%d %H:%i:%S.%#    0003-01-02 08:11:02
125
 
03-01-02 8:11:2.123456  %Y-%m-%d %H:%i:%S.%#    2003-01-02 08:11:02
126
 
2003-01-02 10:11:12 PM  %Y-%m-%d %h:%i:%S %p    2003-01-02 22:11:12
127
 
2003-01-02 01:11:12.12345AM     %Y-%m-%d %h:%i:%S.%f%p  2003-01-02 01:11:12.123450
128
 
2003-01-02 02:11:12.12345AM     %Y-%m-%d %h:%i:%S.%f %p 2003-01-02 02:11:12.123450
129
 
2003-01-02 12:11:12.12345 am    %Y-%m-%d %h:%i:%S.%f%p  2003-01-02 00:11:12.123450
130
 
2003-01-02 11:11:12Pm   %Y-%m-%d %h:%i:%S%p     2003-01-02 23:11:12
131
 
10:20:10        %H:%i:%s        0000-00-00 10:20:10
132
 
10:20:10        %h:%i:%s.%f     0000-00-00 10:20:10
133
 
10:20:10        %T      0000-00-00 10:20:10
134
 
10:20:10AM      %h:%i:%s%p      0000-00-00 10:20:10
135
 
10:20:10AM      %r      0000-00-00 10:20:10
136
 
10:20:10.44AM   %h:%i:%s.%f%p   0000-00-00 10:20:10.440000
137
 
15-01-2001 12:59:58     %d-%m-%Y %H:%i:%S       2001-01-15 12:59:58
138
 
15 September 2001       %d %M %Y        2001-09-15 00:00:00
139
 
15 SEPTEMB 2001 %d %M %Y        2001-09-15 00:00:00
140
 
15 MAY 2001     %d %b %Y        2001-05-15 00:00:00
141
 
15th May 2001   %D %b %Y        2001-05-15 00:00:00
142
 
Sunday 15 MAY 2001      %W %d %b %Y     2001-05-15 00:00:00
143
 
Sund 15 MAY 2001        %W %d %b %Y     2001-05-15 00:00:00
144
 
Tuesday 00 2002 %W %U %Y        2002-01-01 00:00:00
145
 
Thursday 53 1998        %W %u %Y        1998-12-31 00:00:00
146
 
Sunday 01 2001  %W %v %x        2001-01-07 00:00:00
147
 
Tuesday 52 2001 %W %V %X        2002-01-01 00:00:00
148
 
060 2004        %j %Y   2004-02-29 00:00:00
149
 
4 53 1998       %w %u %Y        1998-12-31 00:00:00
150
 
15-01-2001      %d-%m-%Y %H:%i:%S       2001-01-15 00:00:00
151
 
15-01-20        %d-%m-%y        2020-01-15 00:00:00
152
 
15-2001-1       %d-%Y-%c        2001-01-15 00:00:00
153
 
select date,format,concat('',str_to_date(date, format)) as con from t1;
154
 
date    format  con
155
 
2003-01-02 10:11:12     %Y-%m-%d %H:%i:%S       2003-01-02 10:11:12
156
 
03-01-02 8:11:2.123456  %y-%m-%d %H:%i:%S.%#    2003-01-02 08:11:02
157
 
0003-01-02 8:11:2.123456        %Y-%m-%d %H:%i:%S.%#    0003-01-02 08:11:02
158
 
03-01-02 8:11:2.123456  %Y-%m-%d %H:%i:%S.%#    2003-01-02 08:11:02
159
 
2003-01-02 10:11:12 PM  %Y-%m-%d %h:%i:%S %p    2003-01-02 22:11:12
160
 
2003-01-02 01:11:12.12345AM     %Y-%m-%d %h:%i:%S.%f%p  2003-01-02 01:11:12.123450
161
 
2003-01-02 02:11:12.12345AM     %Y-%m-%d %h:%i:%S.%f %p 2003-01-02 02:11:12.123450
162
 
2003-01-02 12:11:12.12345 am    %Y-%m-%d %h:%i:%S.%f%p  2003-01-02 00:11:12.123450
163
 
2003-01-02 11:11:12Pm   %Y-%m-%d %h:%i:%S%p     2003-01-02 23:11:12
164
 
10:20:10        %H:%i:%s        0000-00-00 10:20:10
165
 
10:20:10        %h:%i:%s.%f     0000-00-00 10:20:10
166
 
10:20:10        %T      0000-00-00 10:20:10
167
 
10:20:10AM      %h:%i:%s%p      0000-00-00 10:20:10
168
 
10:20:10AM      %r      0000-00-00 10:20:10
169
 
10:20:10.44AM   %h:%i:%s.%f%p   0000-00-00 10:20:10.440000
170
 
15-01-2001 12:59:58     %d-%m-%Y %H:%i:%S       2001-01-15 12:59:58
171
 
15 September 2001       %d %M %Y        2001-09-15 00:00:00
172
 
15 SEPTEMB 2001 %d %M %Y        2001-09-15 00:00:00
173
 
15 MAY 2001     %d %b %Y        2001-05-15 00:00:00
174
 
15th May 2001   %D %b %Y        2001-05-15 00:00:00
175
 
Sunday 15 MAY 2001      %W %d %b %Y     2001-05-15 00:00:00
176
 
Sund 15 MAY 2001        %W %d %b %Y     2001-05-15 00:00:00
177
 
Tuesday 00 2002 %W %U %Y        2002-01-01 00:00:00
178
 
Thursday 53 1998        %W %u %Y        1998-12-31 00:00:00
179
 
Sunday 01 2001  %W %v %x        2001-01-07 00:00:00
180
 
Tuesday 52 2001 %W %V %X        2002-01-01 00:00:00
181
 
060 2004        %j %Y   2004-02-29 00:00:00
182
 
4 53 1998       %w %u %Y        1998-12-31 00:00:00
183
 
15-01-2001      %d-%m-%Y %H:%i:%S       2001-01-15 00:00:00
184
 
15-01-20        %d-%m-%y        2020-01-15 00:00:00
185
 
15-2001-1       %d-%Y-%c        2001-01-15 00:00:00
186
 
select date,format,cast(str_to_date(date, format) as datetime) as datetime from t1;
187
 
date    format  datetime
188
 
2003-01-02 10:11:12     %Y-%m-%d %H:%i:%S       2003-01-02 10:11:12
189
 
03-01-02 8:11:2.123456  %y-%m-%d %H:%i:%S.%#    2003-01-02 08:11:02
190
 
0003-01-02 8:11:2.123456        %Y-%m-%d %H:%i:%S.%#    0003-01-02 08:11:02
191
 
03-01-02 8:11:2.123456  %Y-%m-%d %H:%i:%S.%#    2003-01-02 08:11:02
192
 
2003-01-02 10:11:12 PM  %Y-%m-%d %h:%i:%S %p    2003-01-02 22:11:12
193
 
2003-01-02 01:11:12.12345AM     %Y-%m-%d %h:%i:%S.%f%p  2003-01-02 01:11:12.123450
194
 
2003-01-02 02:11:12.12345AM     %Y-%m-%d %h:%i:%S.%f %p 2003-01-02 02:11:12.123450
195
 
2003-01-02 12:11:12.12345 am    %Y-%m-%d %h:%i:%S.%f%p  2003-01-02 00:11:12.123450
196
 
2003-01-02 11:11:12Pm   %Y-%m-%d %h:%i:%S%p     2003-01-02 23:11:12
197
 
10:20:10        %H:%i:%s        0000-00-00 10:20:10
198
 
10:20:10        %h:%i:%s.%f     0000-00-00 10:20:10
199
 
10:20:10        %T      0000-00-00 10:20:10
200
 
10:20:10AM      %h:%i:%s%p      0000-00-00 10:20:10
201
 
10:20:10AM      %r      0000-00-00 10:20:10
202
 
10:20:10.44AM   %h:%i:%s.%f%p   0000-00-00 10:20:10.440000
203
 
15-01-2001 12:59:58     %d-%m-%Y %H:%i:%S       2001-01-15 12:59:58
204
 
15 September 2001       %d %M %Y        2001-09-15 00:00:00
205
 
15 SEPTEMB 2001 %d %M %Y        2001-09-15 00:00:00
206
 
15 MAY 2001     %d %b %Y        2001-05-15 00:00:00
207
 
15th May 2001   %D %b %Y        2001-05-15 00:00:00
208
 
Sunday 15 MAY 2001      %W %d %b %Y     2001-05-15 00:00:00
209
 
Sund 15 MAY 2001        %W %d %b %Y     2001-05-15 00:00:00
210
 
Tuesday 00 2002 %W %U %Y        2002-01-01 00:00:00
211
 
Thursday 53 1998        %W %u %Y        1998-12-31 00:00:00
212
 
Sunday 01 2001  %W %v %x        2001-01-07 00:00:00
213
 
Tuesday 52 2001 %W %V %X        2002-01-01 00:00:00
214
 
060 2004        %j %Y   2004-02-29 00:00:00
215
 
4 53 1998       %w %u %Y        1998-12-31 00:00:00
216
 
15-01-2001      %d-%m-%Y %H:%i:%S       2001-01-15 00:00:00
217
 
15-01-20        %d-%m-%y        2020-01-15 00:00:00
218
 
15-2001-1       %d-%Y-%c        2001-01-15 00:00:00
219
 
select date,format,DATE(str_to_date(date, format)) as date2 from t1;
220
 
date    format  date2
221
 
2003-01-02 10:11:12     %Y-%m-%d %H:%i:%S       2003-01-02
222
 
03-01-02 8:11:2.123456  %y-%m-%d %H:%i:%S.%#    2003-01-02
223
 
0003-01-02 8:11:2.123456        %Y-%m-%d %H:%i:%S.%#    0003-01-02
224
 
03-01-02 8:11:2.123456  %Y-%m-%d %H:%i:%S.%#    2003-01-02
225
 
2003-01-02 10:11:12 PM  %Y-%m-%d %h:%i:%S %p    2003-01-02
226
 
2003-01-02 01:11:12.12345AM     %Y-%m-%d %h:%i:%S.%f%p  2003-01-02
227
 
2003-01-02 02:11:12.12345AM     %Y-%m-%d %h:%i:%S.%f %p 2003-01-02
228
 
2003-01-02 12:11:12.12345 am    %Y-%m-%d %h:%i:%S.%f%p  2003-01-02
229
 
2003-01-02 11:11:12Pm   %Y-%m-%d %h:%i:%S%p     2003-01-02
230
 
10:20:10        %H:%i:%s        0000-00-00
231
 
10:20:10        %h:%i:%s.%f     0000-00-00
232
 
10:20:10        %T      0000-00-00
233
 
10:20:10AM      %h:%i:%s%p      0000-00-00
234
 
10:20:10AM      %r      0000-00-00
235
 
10:20:10.44AM   %h:%i:%s.%f%p   0000-00-00
236
 
15-01-2001 12:59:58     %d-%m-%Y %H:%i:%S       2001-01-15
237
 
15 September 2001       %d %M %Y        2001-09-15
238
 
15 SEPTEMB 2001 %d %M %Y        2001-09-15
239
 
15 MAY 2001     %d %b %Y        2001-05-15
240
 
15th May 2001   %D %b %Y        2001-05-15
241
 
Sunday 15 MAY 2001      %W %d %b %Y     2001-05-15
242
 
Sund 15 MAY 2001        %W %d %b %Y     2001-05-15
243
 
Tuesday 00 2002 %W %U %Y        2002-01-01
244
 
Thursday 53 1998        %W %u %Y        1998-12-31
245
 
Sunday 01 2001  %W %v %x        2001-01-07
246
 
Tuesday 52 2001 %W %V %X        2002-01-01
247
 
060 2004        %j %Y   2004-02-29
248
 
4 53 1998       %w %u %Y        1998-12-31
249
 
15-01-2001      %d-%m-%Y %H:%i:%S       2001-01-15
250
 
15-01-20        %d-%m-%y        2020-01-15
251
 
15-2001-1       %d-%Y-%c        2001-01-15
252
 
select date,format,TIME(str_to_date(date, format)) as time from t1;
253
 
date    format  time
254
 
2003-01-02 10:11:12     %Y-%m-%d %H:%i:%S       10:11:12
255
 
03-01-02 8:11:2.123456  %y-%m-%d %H:%i:%S.%#    08:11:02
256
 
0003-01-02 8:11:2.123456        %Y-%m-%d %H:%i:%S.%#    08:11:02
257
 
03-01-02 8:11:2.123456  %Y-%m-%d %H:%i:%S.%#    08:11:02
258
 
2003-01-02 10:11:12 PM  %Y-%m-%d %h:%i:%S %p    22:11:12
259
 
2003-01-02 01:11:12.12345AM     %Y-%m-%d %h:%i:%S.%f%p  01:11:12.123450
260
 
2003-01-02 02:11:12.12345AM     %Y-%m-%d %h:%i:%S.%f %p 02:11:12.123450
261
 
2003-01-02 12:11:12.12345 am    %Y-%m-%d %h:%i:%S.%f%p  00:11:12.123450
262
 
2003-01-02 11:11:12Pm   %Y-%m-%d %h:%i:%S%p     23:11:12
263
 
10:20:10        %H:%i:%s        10:20:10
264
 
10:20:10        %h:%i:%s.%f     10:20:10
265
 
10:20:10        %T      10:20:10
266
 
10:20:10AM      %h:%i:%s%p      10:20:10
267
 
10:20:10AM      %r      10:20:10
268
 
10:20:10.44AM   %h:%i:%s.%f%p   10:20:10.440000
269
 
15-01-2001 12:59:58     %d-%m-%Y %H:%i:%S       12:59:58
270
 
15 September 2001       %d %M %Y        00:00:00
271
 
15 SEPTEMB 2001 %d %M %Y        00:00:00
272
 
15 MAY 2001     %d %b %Y        00:00:00
273
 
15th May 2001   %D %b %Y        00:00:00
274
 
Sunday 15 MAY 2001      %W %d %b %Y     00:00:00
275
 
Sund 15 MAY 2001        %W %d %b %Y     00:00:00
276
 
Tuesday 00 2002 %W %U %Y        00:00:00
277
 
Thursday 53 1998        %W %u %Y        00:00:00
278
 
Sunday 01 2001  %W %v %x        00:00:00
279
 
Tuesday 52 2001 %W %V %X        00:00:00
280
 
060 2004        %j %Y   00:00:00
281
 
4 53 1998       %w %u %Y        00:00:00
282
 
15-01-2001      %d-%m-%Y %H:%i:%S       00:00:00
283
 
15-01-20        %d-%m-%y        00:00:00
284
 
15-2001-1       %d-%Y-%c        00:00:00
285
 
select date,format,concat(TIME(str_to_date(date, format))) as time2 from t1;
286
 
date    format  time2
287
 
2003-01-02 10:11:12     %Y-%m-%d %H:%i:%S       10:11:12
288
 
03-01-02 8:11:2.123456  %y-%m-%d %H:%i:%S.%#    08:11:02
289
 
0003-01-02 8:11:2.123456        %Y-%m-%d %H:%i:%S.%#    08:11:02
290
 
03-01-02 8:11:2.123456  %Y-%m-%d %H:%i:%S.%#    08:11:02
291
 
2003-01-02 10:11:12 PM  %Y-%m-%d %h:%i:%S %p    22:11:12
292
 
2003-01-02 01:11:12.12345AM     %Y-%m-%d %h:%i:%S.%f%p  01:11:12.123450
293
 
2003-01-02 02:11:12.12345AM     %Y-%m-%d %h:%i:%S.%f %p 02:11:12.123450
294
 
2003-01-02 12:11:12.12345 am    %Y-%m-%d %h:%i:%S.%f%p  00:11:12.123450
295
 
2003-01-02 11:11:12Pm   %Y-%m-%d %h:%i:%S%p     23:11:12
296
 
10:20:10        %H:%i:%s        10:20:10
297
 
10:20:10        %h:%i:%s.%f     10:20:10
298
 
10:20:10        %T      10:20:10
299
 
10:20:10AM      %h:%i:%s%p      10:20:10
300
 
10:20:10AM      %r      10:20:10
301
 
10:20:10.44AM   %h:%i:%s.%f%p   10:20:10.440000
302
 
15-01-2001 12:59:58     %d-%m-%Y %H:%i:%S       12:59:58
303
 
15 September 2001       %d %M %Y        00:00:00
304
 
15 SEPTEMB 2001 %d %M %Y        00:00:00
305
 
15 MAY 2001     %d %b %Y        00:00:00
306
 
15th May 2001   %D %b %Y        00:00:00
307
 
Sunday 15 MAY 2001      %W %d %b %Y     00:00:00
308
 
Sund 15 MAY 2001        %W %d %b %Y     00:00:00
309
 
Tuesday 00 2002 %W %U %Y        00:00:00
310
 
Thursday 53 1998        %W %u %Y        00:00:00
311
 
Sunday 01 2001  %W %v %x        00:00:00
312
 
Tuesday 52 2001 %W %V %X        00:00:00
313
 
060 2004        %j %Y   00:00:00
314
 
4 53 1998       %w %u %Y        00:00:00
315
 
15-01-2001      %d-%m-%Y %H:%i:%S       00:00:00
316
 
15-01-20        %d-%m-%y        00:00:00
317
 
15-2001-1       %d-%Y-%c        00:00:00
318
 
select concat('',str_to_date('8:11:2.123456 03-01-02','%H:%i:%S.%f %y-%m-%d'));
319
 
concat('',str_to_date('8:11:2.123456 03-01-02','%H:%i:%S.%f %y-%m-%d'))
320
 
2003-01-02 08:11:02.123456
321
 
truncate table t1;
322
 
insert into t1 values
323
 
('2003-01-02 10:11:12 PM', '%Y-%m-%d %H:%i:%S %p'),
324
 
('2003-01-02 10:11:12.123456', '%Y-%m-%d %h:%i:%S %p'),
325
 
('2003-01-02 10:11:12AM', '%Y-%m-%d %h:%i:%S.%f %p'),
326
 
('2003-01-02 10:11:12AN', '%Y-%m-%d %h:%i:%S%p'),
327
 
('2003-01-02 10:11:12 PM', '%y-%m-%d %H:%i:%S %p'),
328
 
('10:20:10AM', '%H:%i:%s%p'),
329
 
('15 Septembei 2001', '%d %M %Y'),
330
 
('15 Ju 2001', '%d %M %Y'),
331
 
('Sund 15 MA', '%W %d %b %Y'),
332
 
('Thursdai 12 1998', '%W %u %Y'),
333
 
('Sunday 01 2001', '%W %v %X'),
334
 
('Tuesday 52 2001', '%W %V %x'),
335
 
('Tuesday 52 2001', '%W %V %Y'),
336
 
('Tuesday 52 2001', '%W %u %x'),
337
 
('7 53 1998', '%w %u %Y'),
338
 
(NULL, get_format(DATE,'USA'));
339
 
select date,format,str_to_date(date, format) as str_to_date from t1;
340
 
date    format  str_to_date
341
 
2003-01-02 10:11:12 PM  %Y-%m-%d %H:%i:%S %p    NULL
342
 
2003-01-02 10:11:12.123456      %Y-%m-%d %h:%i:%S %p    NULL
343
 
2003-01-02 10:11:12AM   %Y-%m-%d %h:%i:%S.%f %p NULL
344
 
2003-01-02 10:11:12AN   %Y-%m-%d %h:%i:%S%p     NULL
345
 
2003-01-02 10:11:12 PM  %y-%m-%d %H:%i:%S %p    NULL
346
 
10:20:10AM      %H:%i:%s%p      NULL
347
 
15 Septembei 2001       %d %M %Y        NULL
348
 
15 Ju 2001      %d %M %Y        NULL
349
 
Sund 15 MA      %W %d %b %Y     NULL
350
 
Thursdai 12 1998        %W %u %Y        NULL
351
 
Sunday 01 2001  %W %v %X        NULL
352
 
Tuesday 52 2001 %W %V %x        NULL
353
 
Tuesday 52 2001 %W %V %Y        NULL
354
 
Tuesday 52 2001 %W %u %x        NULL
355
 
7 53 1998       %w %u %Y        NULL
356
 
NULL    %m.%d.%Y        NULL
357
 
Warnings:
358
 
Error   1411    Incorrect datetime value: '2003-01-02 10:11:12 PM' for function str_to_date
359
 
Error   1411    Incorrect datetime value: '2003-01-02 10:11:12.123456' for function str_to_date
360
 
Error   1411    Incorrect datetime value: '2003-01-02 10:11:12AM' for function str_to_date
361
 
Error   1411    Incorrect datetime value: '2003-01-02 10:11:12AN' for function str_to_date
362
 
Error   1411    Incorrect datetime value: '2003-01-02 10:11:12 PM' for function str_to_date
363
 
Error   1411    Incorrect datetime value: '10:20:10AM' for function str_to_date
364
 
Error   1411    Incorrect datetime value: '15 Septembei 2001' for function str_to_date
365
 
Error   1411    Incorrect datetime value: '15 Ju 2001' for function str_to_date
366
 
Error   1411    Incorrect datetime value: 'Sund 15 MA' for function str_to_date
367
 
Error   1411    Incorrect datetime value: 'Thursdai 12 1998' for function str_to_date
368
 
Error   1411    Incorrect datetime value: 'Sunday 01 2001' for function str_to_date
369
 
Error   1411    Incorrect datetime value: 'Tuesday 52 2001' for function str_to_date
370
 
Error   1411    Incorrect datetime value: 'Tuesday 52 2001' for function str_to_date
371
 
Error   1411    Incorrect datetime value: 'Tuesday 52 2001' for function str_to_date
372
 
Error   1411    Incorrect datetime value: '7 53 1998' for function str_to_date
373
 
select date,format,concat(str_to_date(date, format),'') as con from t1;
374
 
date    format  con
375
 
2003-01-02 10:11:12 PM  %Y-%m-%d %H:%i:%S %p    NULL
376
 
2003-01-02 10:11:12.123456      %Y-%m-%d %h:%i:%S %p    NULL
377
 
2003-01-02 10:11:12AM   %Y-%m-%d %h:%i:%S.%f %p NULL
378
 
2003-01-02 10:11:12AN   %Y-%m-%d %h:%i:%S%p     NULL
379
 
2003-01-02 10:11:12 PM  %y-%m-%d %H:%i:%S %p    NULL
380
 
10:20:10AM      %H:%i:%s%p      NULL
381
 
15 Septembei 2001       %d %M %Y        NULL
382
 
15 Ju 2001      %d %M %Y        NULL
383
 
Sund 15 MA      %W %d %b %Y     NULL
384
 
Thursdai 12 1998        %W %u %Y        NULL
385
 
Sunday 01 2001  %W %v %X        NULL
386
 
Tuesday 52 2001 %W %V %x        NULL
387
 
Tuesday 52 2001 %W %V %Y        NULL
388
 
Tuesday 52 2001 %W %u %x        NULL
389
 
7 53 1998       %w %u %Y        NULL
390
 
NULL    %m.%d.%Y        NULL
391
 
Warnings:
392
 
Error   1411    Incorrect datetime value: '2003-01-02 10:11:12 PM' for function str_to_date
393
 
Error   1411    Incorrect datetime value: '2003-01-02 10:11:12.123456' for function str_to_date
394
 
Error   1411    Incorrect datetime value: '2003-01-02 10:11:12AM' for function str_to_date
395
 
Error   1411    Incorrect datetime value: '2003-01-02 10:11:12AN' for function str_to_date
396
 
Error   1411    Incorrect datetime value: '2003-01-02 10:11:12 PM' for function str_to_date
397
 
Error   1411    Incorrect datetime value: '10:20:10AM' for function str_to_date
398
 
Error   1411    Incorrect datetime value: '15 Septembei 2001' for function str_to_date
399
 
Error   1411    Incorrect datetime value: '15 Ju 2001' for function str_to_date
400
 
Error   1411    Incorrect datetime value: 'Sund 15 MA' for function str_to_date
401
 
Error   1411    Incorrect datetime value: 'Thursdai 12 1998' for function str_to_date
402
 
Error   1411    Incorrect datetime value: 'Sunday 01 2001' for function str_to_date
403
 
Error   1411    Incorrect datetime value: 'Tuesday 52 2001' for function str_to_date
404
 
Error   1411    Incorrect datetime value: 'Tuesday 52 2001' for function str_to_date
405
 
Error   1411    Incorrect datetime value: 'Tuesday 52 2001' for function str_to_date
406
 
Error   1411    Incorrect datetime value: '7 53 1998' for function str_to_date
407
 
truncate table t1;
408
 
insert into t1 values
409
 
('10:20:10AM', '%h:%i:%s'),
410
 
('2003-01-02 10:11:12', '%Y-%m-%d %h:%i:%S'),
411
 
('03-01-02 10:11:12 PM', '%Y-%m-%d %h:%i:%S %p');
412
 
select date,format,str_to_date(date, format) as str_to_date from t1;
413
 
date    format  str_to_date
414
 
10:20:10AM      %h:%i:%s        0000-00-00 10:20:10
415
 
2003-01-02 10:11:12     %Y-%m-%d %h:%i:%S       2003-01-02 10:11:12
416
 
03-01-02 10:11:12 PM    %Y-%m-%d %h:%i:%S %p    2003-01-02 22:11:12
417
 
Warnings:
418
 
Warning 1292    Incorrect datetime value: '10:20:10AM'
419
 
select date,format,concat(str_to_date(date, format),'') as con from t1;
420
 
date    format  con
421
 
10:20:10AM      %h:%i:%s        0000-00-00 10:20:10
422
 
2003-01-02 10:11:12     %Y-%m-%d %h:%i:%S       2003-01-02 10:11:12
423
 
03-01-02 10:11:12 PM    %Y-%m-%d %h:%i:%S %p    2003-01-02 22:11:12
424
 
Warnings:
425
 
Warning 1292    Incorrect datetime value: '10:20:10AM'
426
 
drop table t1;
427
 
select get_format(DATE, 'USA') as a;
428
 
a
429
 
%m.%d.%Y
430
 
select get_format(TIME, 'internal') as a;
431
 
a
432
 
%H%i%s
433
 
select get_format(DATETIME, 'eur') as a;
434
 
a
435
 
%Y-%m-%d %H.%i.%s
436
 
select get_format(TIMESTAMP, 'eur') as a;
437
 
a
438
 
%Y-%m-%d %H.%i.%s
439
 
select get_format(DATE, 'TEST') as a;
440
 
a
441
 
NULL
442
 
select str_to_date('15-01-2001 12:59:59', GET_FORMAT(DATE,'USA'));
443
 
str_to_date('15-01-2001 12:59:59', GET_FORMAT(DATE,'USA'))
444
 
NULL
445
 
Warnings:
446
 
Error   1411    Incorrect datetime value: '15-01-2001 12:59:59' for function str_to_date
447
 
explain extended select makedate(1997,1), addtime("31.12.97 11.59.59.999999 PM", "1 1.1.1.000002"),subtime("31.12.97 11.59.59.999999 PM", "1 1.1.1.000002"),timediff("01.01.97 11:59:59.000001 PM","31.12.95 11:59:59.000002 PM"),cast(str_to_date("15-01-2001 12:59:59", "%d-%m-%Y %H:%i:%S") as TIME), maketime(23,11,12),microsecond("1997-12-31 23:59:59.000001");
448
 
id      select_type     table   type    possible_keys   key     key_len ref     rows    filtered        Extra
449
 
1       SIMPLE  NULL    NULL    NULL    NULL    NULL    NULL    NULL    NULL    No tables used
450
 
Warnings:
451
 
Note    1003    select makedate(1997,1) AS `makedate(1997,1)`,addtime('31.12.97 11.59.59.999999 PM','1 1.1.1.000002') AS `addtime("31.12.97 11.59.59.999999 PM", "1 1.1.1.000002")`,subtime('31.12.97 11.59.59.999999 PM','1 1.1.1.000002') AS `subtime("31.12.97 11.59.59.999999 PM", "1 1.1.1.000002")`,timediff('01.01.97 11:59:59.000001 PM','31.12.95 11:59:59.000002 PM') AS `timediff("01.01.97 11:59:59.000001 PM","31.12.95 11:59:59.000002 PM")`,cast(str_to_date('15-01-2001 12:59:59','%d-%m-%Y %H:%i:%S') as time) AS `cast(str_to_date("15-01-2001 12:59:59", "%d-%m-%Y %H:%i:%S") as TIME)`,maketime(23,11,12) AS `maketime(23,11,12)`,microsecond('1997-12-31 23:59:59.000001') AS `microsecond("1997-12-31 23:59:59.000001")`
452
 
create table t1 (d date);
453
 
insert into t1 values ('2004-07-14'),('2005-07-14');
454
 
select date_format(d,"%d") from t1 order by 1;
455
 
date_format(d,"%d")
456
 
14
457
 
14
458
 
drop table t1;
459
 
select str_to_date("2003-....01ABCD-02 10:11:12.0012", "%Y-%.%m%@-%d %H:%i:%S.%f") as a;
460
 
a
461
 
2003-01-02 10:11:12.001200
462
 
create table t1 select str_to_date("2003-01-02 10:11:12.0012", "%Y-%m-%d %H:%i:%S.%f") as f1,
463
 
str_to_date("10:11:12.0012", "%H:%i:%S.%f") as f2,
464
 
str_to_date("2003-01-02", "%Y-%m-%d") as f3,
465
 
str_to_date("02", "%d") as f4, str_to_date("02 10", "%d %H") as f5;
466
 
describe t1;
467
 
Field   Type    Null    Key     Default Extra
468
 
f1      datetime        YES             NULL    
469
 
f2      time    YES             NULL    
470
 
f3      date    YES             NULL    
471
 
f4      date    YES             NULL    
472
 
f5      time    YES             NULL    
473
 
select * from t1;
474
 
f1      f2      f3      f4      f5
475
 
2003-01-02 10:11:12     10:11:12        2003-01-02      0000-00-02      58:00:00
476
 
drop table t1;
477
 
create table t1 select "02 10" as a, "%d %H" as b;
478
 
select str_to_date(a,b) from t1;
479
 
str_to_date(a,b)
480
 
0000-00-02 10:00:00
481
 
create table t2 select str_to_date(a,b) from t1;
482
 
describe t2;
483
 
Field   Type    Null    Key     Default Extra
484
 
str_to_date(a,b)        datetime        YES             NULL    
485
 
select str_to_date("2003-01-02 10:11:12.0012", "%Y-%m-%d %H:%i:%S.%f") as f1,
486
 
str_to_date("2003-01-02 10:11:12.0012", "%Y-%m-%d %H:%i:%S") as f2,
487
 
str_to_date("2003-01-02", "%Y-%m-%d") as f3,
488
 
str_to_date("02 10:11:12", "%d %H:%i:%S.%f") as f4,
489
 
str_to_date("02 10:11:12", "%d %H:%i:%S") as f5,
490
 
str_to_date("02 10", "%d %f") as f6;
491
 
f1      f2      f3      f4      f5      f6
492
 
2003-01-02 10:11:12.001200      2003-01-02 10:11:12     2003-01-02      58:11:12        58:11:12        48:00:00.100000
493
 
Warnings:
494
 
Warning 1292    Truncated incorrect datetime value: '2003-01-02 10:11:12.0012'
495
 
drop table t1, t2;
496
 
select str_to_date("2003-01-02 10:11:12.0012ABCD", "%Y-%m-%d %H:%i:%S.%f") as f1,
497
 
addtime("-01:01:01.01 GGG", "-23:59:59.1") as f2,
498
 
microsecond("1997-12-31 23:59:59.01XXXX") as f3;
499
 
f1      f2      f3
500
 
2003-01-02 10:11:12.001200      -25:01:00.110000        10000
501
 
Warnings:
502
 
Warning 1292    Truncated incorrect datetime value: '2003-01-02 10:11:12.0012ABCD'
503
 
Warning 1292    Truncated incorrect time value: '-01:01:01.01 GGG'
504
 
Warning 1292    Truncated incorrect time value: '1997-12-31 23:59:59.01XXXX'
505
 
select str_to_date("2003-04-05  g", "%Y-%m-%d") as f1,
506
 
str_to_date("2003-04-05 10:11:12.101010234567", "%Y-%m-%d %H:%i:%S.%f") as f2;
507
 
f1      f2
508
 
2003-04-05      2003-04-05 10:11:12.101010
509
 
Warnings:
510
 
Warning 1292    Truncated incorrect date value: '2003-04-05  g'
511
 
Warning 1292    Truncated incorrect datetime value: '2003-04-05 10:11:12.101010234567'
512
 
create table t1 (f1 datetime);
513
 
insert into t1 (f1) values ("2005-01-01");
514
 
insert into t1 (f1) values ("2005-02-01");
515
 
select date_format(f1, "%m") as d1, date_format(f1, "%M") as d2 from t1 order by date_format(f1, "%M");
516
 
d1      d2
517
 
02      February
518
 
01      January
519
 
drop table t1;
520
 
select str_to_date( 1, NULL );
521
 
str_to_date( 1, NULL )
522
 
NULL
523
 
select str_to_date( NULL, 1 );
524
 
str_to_date( NULL, 1 )
525
 
NULL
526
 
select str_to_date( 1, IF(1=1,NULL,NULL) );
527
 
str_to_date( 1, IF(1=1,NULL,NULL) )
528
 
NULL
529
 
SELECT TIME_FORMAT("24:00:00", '%r');
530
 
TIME_FORMAT("24:00:00", '%r')
531
 
12:00:00 AM
532
 
SELECT TIME_FORMAT("00:00:00", '%r');
533
 
TIME_FORMAT("00:00:00", '%r')
534
 
12:00:00 AM
535
 
SELECT TIME_FORMAT("12:00:00", '%r');
536
 
TIME_FORMAT("12:00:00", '%r')
537
 
12:00:00 PM
538
 
SELECT TIME_FORMAT("15:00:00", '%r');
539
 
TIME_FORMAT("15:00:00", '%r')
540
 
03:00:00 PM
541
 
SELECT TIME_FORMAT("01:00:00", '%r');
542
 
TIME_FORMAT("01:00:00", '%r')
543
 
01:00:00 AM
544
 
SELECT TIME_FORMAT("25:00:00", '%r');
545
 
TIME_FORMAT("25:00:00", '%r')
546
 
01:00:00 AM
547
 
SELECT TIME_FORMAT("00:00:00", '%l %p');
548
 
TIME_FORMAT("00:00:00", '%l %p')
549
 
12 AM
550
 
SELECT TIME_FORMAT("01:00:00", '%l %p');
551
 
TIME_FORMAT("01:00:00", '%l %p')
552
 
1 AM
553
 
SELECT TIME_FORMAT("12:00:00", '%l %p');
554
 
TIME_FORMAT("12:00:00", '%l %p')
555
 
12 PM
556
 
SELECT TIME_FORMAT("23:00:00", '%l %p');
557
 
TIME_FORMAT("23:00:00", '%l %p')
558
 
11 PM
559
 
SELECT TIME_FORMAT("24:00:00", '%l %p');
560
 
TIME_FORMAT("24:00:00", '%l %p')
561
 
12 AM
562
 
SELECT TIME_FORMAT("25:00:00", '%l %p');
563
 
TIME_FORMAT("25:00:00", '%l %p')
564
 
1 AM
565
 
SELECT DATE_FORMAT('%Y-%m-%d %H:%i:%s', 1151414896);
566
 
DATE_FORMAT('%Y-%m-%d %H:%i:%s', 1151414896)
567
 
NULL
568
 
Warnings:
569
 
Warning 1292    Incorrect datetime value: '%Y-%m-%d %H:%i:%s'
570
 
select str_to_date('04 /30/2004', '%m /%d/%Y');
571
 
str_to_date('04 /30/2004', '%m /%d/%Y')
572
 
2004-04-30
573
 
select str_to_date('04/30 /2004', '%m /%d /%Y');
574
 
str_to_date('04/30 /2004', '%m /%d /%Y')
575
 
2004-04-30
576
 
select str_to_date('04/30/2004 ', '%m/%d/%Y ');
577
 
str_to_date('04/30/2004 ', '%m/%d/%Y ')
578
 
2004-04-30
579
 
"End of 4.1 tests"