174
174
create table t1 (d date, dt datetime, t timestamp, c char(10));
175
175
insert into t1 values (null, null, null, null);
177
--error ER_INVALID_DATE_VALUE # Bad dates...
176
--error 1686 # Bad dates...
178
177
insert into t1 values ("0000-00-00", "0000-00-00", "0000-00-00", "0000-00-00");
180
--error ER_INVALID_DATETIME_VALUE # 0000-00-00 is a bad date
178
--error 1686 # 0000-00-00 is a bad date
181
179
select dayofyear("0000-00-00"),dayofyear(d),dayofyear(dt),dayofyear(t),dayofyear(c) from t1;
183
--error ER_INVALID_DATETIME_VALUE # 0000-00-00 is a bad date
180
--error 1686 # 0000-00-00 is a bad date
184
181
select dayofmonth("0000-00-00"),dayofmonth(d),dayofmonth(dt),dayofmonth(t),dayofmonth(c) from t1;
186
--error ER_INVALID_DATETIME_VALUE # 0000-00-00 is not a damn date.
182
--error 1686 # 0000-00-00 is not a damn date.
187
183
select month("0000-00-00"),month(d),month(dt),month(t),month(c) from t1;
189
--error ER_INVALID_DATETIME_VALUE # 0000-00-00 not a date
184
--error 1686 # 0000-00-00 not a date
190
185
select quarter("0000-00-00"),quarter(d),quarter(dt),quarter(t),quarter(c) from t1;
192
--error ER_INVALID_DATETIME_VALUE # Argh. 0000-00-00 is not a date.
186
--error 1686 # Argh. 0000-00-00 is not a date.
193
187
select year("0000-00-00"),year(d),year(dt),year(t),year(c) from t1;
195
--error ER_INVALID_DATETIME_VALUE # Bad datetime
188
--error 1686 # Bad datetime
196
189
select to_days("0000-00-00"),to_days(d),to_days(dt),to_days(c) from t1;
198
--error ER_INVALID_DATETIME_VALUE # Ugh. bad datetime
190
--error 1686 # Ugh. bad datetime
199
191
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;
251
243
# check for invalid dates
253
# Legal, Drizzle has 64bit timestamp
254
--error ER_INVALID_UNIX_TIMESTAMP_VALUE # Bad timestamp
255
246
select unix_timestamp('2039-01-20 01:00:00');
257
--error ER_INVALID_UNIX_TIMESTAMP_VALUE # Bad timestamp
258
247
select unix_timestamp('1968-01-20 01:00:00');
260
--error ER_INVALID_UNIX_TIMESTAMP_VALUE # Bad timestamp
261
249
select unix_timestamp('2038-02-10 01:00:00');
263
--error ER_INVALID_UNIX_TIMESTAMP_VALUE # Bad timestamp
264
250
select unix_timestamp('1969-11-20 01:00:00');
266
--error ER_INVALID_UNIX_TIMESTAMP_VALUE # Bad timestamp
267
252
select unix_timestamp('2038-01-20 01:00:00');
269
--error ER_INVALID_UNIX_TIMESTAMP_VALUE # Bad timestamp
270
253
select unix_timestamp('1969-12-30 01:00:00');
275
258
select unix_timestamp('2038-01-17 12:00:00');
261
# Check positive shift. (it happens only on
262
# platfroms with time_t, such as QNX)
264
select unix_timestamp('1970-01-01 03:00:01');
277
266
# check bad date, close to the boundary (we cut them off in the very end)
278
select unix_timestamp('2038-01-19 03:14:07');
267
select unix_timestamp('2038-01-19 07:14:07');
282
271
# Test types from + INTERVAL
285
CREATE TABLE t1 (datetime_arg datetime, timestamp_arg timestamp, date_arg date);
274
CREATE TABLE t1 (datetime datetime, timestamp timestamp, date date);
286
275
INSERT INTO t1 values ("2001-01-02 03:04:05", "2002-01-02 03:04:05", "2003-01-02");
287
276
SELECT * from t1;
288
277
select date_add("1997-12-31",INTERVAL 1 SECOND);
289
278
select date_add("1997-12-31",INTERVAL "1 1" YEAR_MONTH);
291
select date_add(datetime_arg, INTERVAL 1 SECOND) from t1;
292
select date_add(datetime_arg, INTERVAL 1 YEAR) from t1;
280
select date_add(datetime, INTERVAL 1 SECOND) from t1;
281
select date_add(datetime, INTERVAL 1 YEAR) from t1;
294
select date_add(date_arg, INTERVAL 1 SECOND) from t1;
295
select date_add(date_arg, INTERVAL 1 MINUTE) from t1;
296
select date_add(date_arg, INTERVAL 1 HOUR) from t1;
297
select date_add(date_arg, INTERVAL 1 DAY) from t1;
298
select date_add(date_arg, INTERVAL 1 MONTH) from t1;
299
select date_add(date_arg, INTERVAL 1 YEAR) from t1;
300
select date_add(date_arg, INTERVAL "1:1" MINUTE_SECOND) from t1;
301
select date_add(date_arg, INTERVAL "1:1" HOUR_MINUTE) from t1;
302
select date_add(date_arg, INTERVAL "1:1" DAY_HOUR) from t1;
303
select date_add(date_arg, INTERVAL "1 1" YEAR_MONTH) from t1;
304
select date_add(date_arg, INTERVAL "1:1:1" HOUR_SECOND) from t1;
305
select date_add(date_arg, INTERVAL "1 1:1" DAY_MINUTE) from t1;
306
select date_add(date_arg, INTERVAL "1 1:1:1" DAY_SECOND) from t1;
307
select date_add(date_arg, INTERVAL "1" WEEK) from t1;
308
select date_add(date_arg, INTERVAL "1" QUARTER) from t1;
309
select timestampadd(MINUTE, 1, date_arg) from t1;
310
select timestampadd(WEEK, 1, date_arg) from t1;
311
select timestampadd(SQL_TSI_SECOND, 1, date_arg) from t1;
283
select date_add(date,INTERVAL 1 SECOND) from t1;
284
select date_add(date,INTERVAL 1 MINUTE) from t1;
285
select date_add(date,INTERVAL 1 HOUR) from t1;
286
select date_add(date,INTERVAL 1 DAY) from t1;
287
select date_add(date,INTERVAL 1 MONTH) from t1;
288
select date_add(date,INTERVAL 1 YEAR) from t1;
289
select date_add(date,INTERVAL "1:1" MINUTE_SECOND) from t1;
290
select date_add(date,INTERVAL "1:1" HOUR_MINUTE) from t1;
291
select date_add(date,INTERVAL "1:1" DAY_HOUR) from t1;
292
select date_add(date,INTERVAL "1 1" YEAR_MONTH) from t1;
293
select date_add(date,INTERVAL "1:1:1" HOUR_SECOND) from t1;
294
select date_add(date,INTERVAL "1 1:1" DAY_MINUTE) from t1;
295
select date_add(date,INTERVAL "1 1:1:1" DAY_SECOND) from t1;
296
select date_add(date,INTERVAL "1" WEEK) from t1;
297
select date_add(date,INTERVAL "1" QUARTER) from t1;
298
select timestampadd(MINUTE, 1, date) from t1;
299
select timestampadd(WEEK, 1, date) from t1;
300
select timestampadd(SQL_TSI_SECOND, 1, date) from t1;
312
301
# mysqltest.c discards an expected 'deprecated' warning on prepare stage
313
302
--disable_ps_protocol
314
select timestampadd(SQL_TSI_FRAC_SECOND, 1, date_arg) from t1;
303
select timestampadd(SQL_TSI_FRAC_SECOND, 1, date) from t1;
315
304
--enable_ps_protocol
317
306
select timestampdiff(MONTH, '2001-02-01', '2001-05-01') as a;
392
381
# Test SAPDB UTC_% functions. This part is TZ dependant (It is supposed that
393
382
# TZ variable set to GMT-3
395
select strcmp(date_sub(localtimestamp(), interval 0 hour), utc_timestamp())=0;
396
select strcmp(date_format(date_sub(localtimestamp(), interval 0 hour),"%Y-%m-%d"), utc_date())=0;
384
select strcmp(date_sub(localtimestamp(), interval 3 hour), utc_timestamp())=0;
385
select strcmp(date_format(date_sub(localtimestamp(), interval 3 hour),"%Y-%m-%d"), utc_date())=0;
397
386
select strcmp(date_format(utc_timestamp(),"%Y-%m-%d"), utc_date())=0;
399
388
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),weekday(curdate())-weekday(now()),dayname("1962-03-03"),unix_timestamp(),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);