118
118
# select cast(str_to_date('15-01-2001 12:59:59', '%d-%m-%Y %H:%i:%S') as TIME);
121
# Test of str_to_date
124
# PS doesn't support fraction of a seconds
125
--disable_ps_protocol
126
select str_to_date(concat('15-01-2001',' 2:59:58.999'),
127
concat('%d-%m-%Y',' ','%H:%i:%s.%f'));
128
select STR_TO_DATE('2004.12.12 22.30.61','%Y.%m.%d %T');
131
create table t1 (date char(30), format char(30) not null);
132
insert into t1 values
133
('2003-01-02 10:11:12', '%Y-%m-%d %H:%i:%S'),
134
('03-01-02 8:11:2.123456', '%y-%m-%d %H:%i:%S.%#'),
135
('0003-01-02 8:11:2.123456', '%Y-%m-%d %H:%i:%S.%#'),
136
('03-01-02 8:11:2.123456', '%Y-%m-%d %H:%i:%S.%#'),
137
('2003-01-02 10:11:12 PM', '%Y-%m-%d %h:%i:%S %p'),
138
('2003-01-02 01:11:12.12345AM', '%Y-%m-%d %h:%i:%S.%f%p'),
139
('2003-01-02 02:11:12.12345AM', '%Y-%m-%d %h:%i:%S.%f %p'),
140
('2003-01-02 12:11:12.12345 am', '%Y-%m-%d %h:%i:%S.%f%p'),
141
('2003-01-02 11:11:12Pm', '%Y-%m-%d %h:%i:%S%p'),
142
('10:20:10', '%H:%i:%s'),
143
('10:20:10', '%h:%i:%s.%f'),
145
('10:20:10AM', '%h:%i:%s%p'),
146
('10:20:10AM', '%r'),
147
('10:20:10.44AM', '%h:%i:%s.%f%p'),
148
('15-01-2001 12:59:58', '%d-%m-%Y %H:%i:%S'),
149
('15 September 2001', '%d %M %Y'),
150
('15 SEPTEMB 2001', '%d %M %Y'),
151
('15 MAY 2001', '%d %b %Y'),
152
('15th May 2001', '%D %b %Y'),
153
('Sunday 15 MAY 2001', '%W %d %b %Y'),
154
('Sund 15 MAY 2001', '%W %d %b %Y'),
155
('Tuesday 00 2002', '%W %U %Y'),
156
('Thursday 53 1998', '%W %u %Y'),
157
('Sunday 01 2001', '%W %v %x'),
158
('Tuesday 52 2001', '%W %V %X'),
159
('060 2004', '%j %Y'),
160
('4 53 1998', '%w %u %Y'),
161
('15-01-2001', '%d-%m-%Y %H:%i:%S'),
162
('15-01-20', '%d-%m-%y'),
163
('15-2001-1', '%d-%Y-%c');
165
# PS doesn't support fractional seconds
166
--disable_ps_protocol
167
select date,format,str_to_date(date, format) as str_to_date from t1;
169
select date,format,concat('',str_to_date(date, format)) as con from t1;
171
select date,format,cast(str_to_date(date, format) as datetime) as datetime from t1;
172
select date,format,DATE(str_to_date(date, format)) as date2 from t1;
173
select date,format,TIME(str_to_date(date, format)) as time from t1;
174
select date,format,concat(TIME(str_to_date(date, format))) as time2 from t1;
175
# Test small bug in %f handling
176
select concat('',str_to_date('8:11:2.123456 03-01-02','%H:%i:%S.%f %y-%m-%d'));
178
# Test wrong dates or converion specifiers
181
insert into t1 values
182
('2003-01-02 10:11:12 PM', '%Y-%m-%d %H:%i:%S %p'),
183
('2003-01-02 10:11:12.123456', '%Y-%m-%d %h:%i:%S %p'),
184
('2003-01-02 10:11:12AM', '%Y-%m-%d %h:%i:%S.%f %p'),
185
('2003-01-02 10:11:12AN', '%Y-%m-%d %h:%i:%S%p'),
186
('2003-01-02 10:11:12 PM', '%y-%m-%d %H:%i:%S %p'),
187
('10:20:10AM', '%H:%i:%s%p'),
188
('15 Septembei 2001', '%d %M %Y'),
189
('15 Ju 2001', '%d %M %Y'),
190
('Sund 15 MA', '%W %d %b %Y'),
191
('Thursdai 12 1998', '%W %u %Y'),
192
('Sunday 01 2001', '%W %v %X'),
193
('Tuesday 52 2001', '%W %V %x'),
194
('Tuesday 52 2001', '%W %V %Y'),
195
('Tuesday 52 2001', '%W %u %x'),
196
('7 53 1998', '%w %u %Y'),
197
(NULL, get_format(DATE,'USA'));
198
select date,format,str_to_date(date, format) as str_to_date from t1;
199
select date,format,concat(str_to_date(date, format),'') as con from t1;
201
# Test 'maybe' date formats and 'strange but correct' results
204
insert into t1 values
205
('10:20:10AM', '%h:%i:%s'),
206
('2003-01-02 10:11:12', '%Y-%m-%d %h:%i:%S'),
207
('03-01-02 10:11:12 PM', '%Y-%m-%d %h:%i:%S %p');
209
select date,format,str_to_date(date, format) as str_to_date from t1;
210
select date,format,concat(str_to_date(date, format),'') as con from t1;
216
121
# Test of get_format
219
124
select get_format(DATE, 'USA') as a;
220
select get_format(TIME, 'internal') as a;
221
125
select get_format(DATETIME, 'eur') as a;
222
126
select get_format(TIMESTAMP, 'eur') as a;
223
127
select get_format(DATE, 'TEST') as a;
224
select str_to_date('15-01-2001 12:59:59', GET_FORMAT(DATE,'USA'));
226
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");
129
explain extended select makedate(1997,1), subtime("31.12.97 11.59.59.999999 PM", "1 1.1.1.000002"),microsecond("1997-12-31 23:59:59.000001");
229
132
# Test of date_format()
238
# Commenting out all str_to_date(). It's an abomination
239
# and hopefully we can get rid of it.
241
# I mean, seriously, this: str_to_date("02 10", "%d %H") is supposed to produce a date!?
243
# PS doesn't support fractional seconds
244
#--disable_ps_protocol
245
#select str_to_date("2003-....01ABCD-02 10:11:12.0012", "%Y-%.%m%@-%d %H:%i:%S.%f") as a;
247
#create table t1 select str_to_date("2003-01-02 10:11:12.0012", "%Y-%m-%d %H:%i:%S.%f") as f1,
248
# str_to_date("10:11:12.0012", "%H:%i:%S.%f") as f2,
249
# str_to_date("2003-01-02", "%Y-%m-%d") as f3,
250
# str_to_date("02", "%d") as f4, str_to_date("02 10", "%d %H") as f5;
255
#create table t1 select "02 10" as a, "%d %H" as b;
256
#select str_to_date(a,b) from t1;
257
#create table t2 select str_to_date(a,b) from t1;
259
#select str_to_date("2003-01-02 10:11:12.0012", "%Y-%m-%d %H:%i:%S.%f") as f1,
260
# str_to_date("2003-01-02 10:11:12.0012", "%Y-%m-%d %H:%i:%S") as f2,
261
# str_to_date("2003-01-02", "%Y-%m-%d") as f3,
262
# str_to_date("02 10:11:12", "%d %H:%i:%S.%f") as f4,
263
# str_to_date("02 10:11:12", "%d %H:%i:%S") as f5,
264
# str_to_date("02 10", "%d %f") as f6;
266
#--error 1686 # These are bad datetimes...
267
#select str_to_date("2003-01-02 10:11:12.0012ABCD", "%Y-%m-%d %H:%i:%S.%f") as f1,
268
# addtime("-01:01:01.01 GGG", "-23:59:59.1") as f2,
269
# microsecond("1997-12-31 23:59:59.01XXXX") as f3;
271
#select str_to_date("2003-04-05 g", "%Y-%m-%d") as f1,
272
# str_to_date("2003-04-05 10:11:12.101010234567", "%Y-%m-%d %H:%i:%S.%f") as f2;
273
#--enable_ps_protocol
278
143
create table t1 (f1 datetime);