~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to mysql-test/r/func_time.result

  • Committer: Brian Aker
  • Date: 2008-07-08 16:17:31 UTC
  • Revision ID: brian@tangent.org-20080708161731-io36j7igglok79py
DATE cleanup.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
drop table if exists t1,t2,t3;
 
2
set time_zone="+03:00";
2
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");
3
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")
4
5
1996-01-01      31      1       5
11
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;
12
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
13
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
14
34
select date_format("1997-01-02 03:04:05", "%M %W %D %Y %y %m %d %h %i %s %w");
15
35
date_format("1997-01-02 03:04:05", "%M %W %D %Y %y %m %d %h %i %s %w")
16
36
January Thursday 2nd 1997 97 01 02 03 04 05 4
23
43
select month("1997-01-02"),year("98-02-03"),dayofyear("1997-12-31");
24
44
month("1997-01-02")     year("98-02-03")        dayofyear("1997-12-31")
25
45
1       1998    365
26
 
select month("2001-02-00"),year("2001-01-01");
27
 
ERROR HY000: Received an invalid datetime value '2001-02-00'.
28
 
select DAYOFYEAR("1997-03-03"), QUARTER(980303);
29
 
DAYOFYEAR("1997-03-03") QUARTER(980303)
30
 
62      1
 
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
31
52
select HOUR("1997-03-03 23:03:22"), MINUTE("23:03:22"), SECOND(230322);
32
53
HOUR("1997-03-03 23:03:22")     MINUTE("23:03:22")      SECOND(230322)
33
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;
34
128
select date_format('1998-12-31','%x-%v'),date_format('1999-01-01','%x-%v');
35
129
date_format('1998-12-31','%x-%v')       date_format('1999-01-01','%x-%v')
36
130
1998-53 1998-53
241
335
extract(DAY_HOUR FROM "1999-01-02 10:11:12")
242
336
210
243
337
select extract(DAY_MINUTE FROM "02 10:11:12");
244
 
ERROR HY000: Received an invalid datetime value '02 10:11:12'.
 
338
extract(DAY_MINUTE FROM "02 10:11:12")
 
339
21011
245
340
select extract(DAY_SECOND FROM "225 10:11:12");
246
 
ERROR HY000: Received an invalid datetime value '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'
247
345
select extract(HOUR FROM "1999-01-02 10:11:12");
248
346
extract(HOUR FROM "1999-01-02 10:11:12")
249
347
10
263
361
extract(SECOND FROM "1999-01-02 10:11:12")
264
362
12
265
363
select extract(MONTH FROM "2001-02-00");
266
 
ERROR HY000: Received an invalid datetime value '2001-02-00'.
 
364
extract(MONTH FROM "2001-02-00")
 
365
2
267
366
SELECT EXTRACT(QUARTER FROM '2004-01-15') AS quarter;
268
367
quarter
269
368
1
300
399
SELECT EXTRACT(QUARTER FROM '2004-12-15') AS quarter;
301
400
quarter
302
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
303
408
SELECT "1900-01-01 00:00:00" + INTERVAL 2147483648 SECOND;
304
409
"1900-01-01 00:00:00" + INTERVAL 2147483648 SECOND
305
410
1968-01-20 03:14:08
309
414
SELECT "1900-01-01 00:00:00" + INTERVAL "100000000:214748364700" MINUTE_SECOND;
310
415
"1900-01-01 00:00:00" + INTERVAL "100000000:214748364700" MINUTE_SECOND
311
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
312
441
SELECT "1900-01-01 00:00:00" + INTERVAL "1000000000:214748364700" MINUTE_SECOND;
313
442
"1900-01-01 00:00:00" + INTERVAL "1000000000:214748364700" MINUTE_SECOND
314
443
NULL
326
455
create table t1 (id int);
327
456
create table t2 (id int, date date);
328
457
insert into t1 values (1);
329
 
insert into t2 values (1, NULL);
 
458
insert into t2 values (1, "0000-00-00");
330
459
insert into t1 values (2);
331
460
insert into t2 values (2, "2000-01-01");
332
461
select monthname(date) from t1 inner join t2 on t1.id = t2.id;
333
462
monthname(date)
334
463
NULL
335
 
NULL
 
464
January
336
465
select monthname(date) from t1 inner join t2 on t1.id = t2.id order by t1.id;
337
466
monthname(date)
338
467
NULL
339
 
NULL
 
468
January
340
469
drop table t1,t2;
341
 
CREATE TEMPORARY TABLE t1 (updated text) ENGINE=MyISAM;
 
470
CREATE TABLE t1 (updated text) ENGINE=MyISAM;
342
471
INSERT INTO t1 VALUES ('');
343
472
SELECT month(updated) from t1;
344
 
ERROR HY000: Received an invalid datetime value ''.
 
473
month(updated)
 
474
NULL
 
475
Warnings:
 
476
Warning 1292    Incorrect datetime value: ''
345
477
SELECT year(updated) from t1;
346
 
ERROR HY000: Received an invalid datetime value ''.
 
478
year(updated)
 
479
NULL
 
480
Warnings:
 
481
Warning 1292    Incorrect datetime value: ''
347
482
drop table t1;
348
483
create table t1 (d date, dt datetime, t timestamp, c char(10));
349
 
insert into t1 values (null, null, null, null);
350
484
insert into t1 values ("0000-00-00", "0000-00-00", "0000-00-00", "0000-00-00");
351
 
ERROR HY000: Received an invalid datetime value '0000-00-00'.
352
485
select dayofyear("0000-00-00"),dayofyear(d),dayofyear(dt),dayofyear(t),dayofyear(c) from t1;
353
 
ERROR HY000: Received an invalid datetime value '0000-00-00'.
 
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'
354
491
select dayofmonth("0000-00-00"),dayofmonth(d),dayofmonth(dt),dayofmonth(t),dayofmonth(c) from t1;
355
 
ERROR HY000: Received an invalid datetime value '0000-00-00'.
 
492
dayofmonth("0000-00-00")        dayofmonth(d)   dayofmonth(dt)  dayofmonth(t)   dayofmonth(c)
 
493
0       0       0       0       0
356
494
select month("0000-00-00"),month(d),month(dt),month(t),month(c) from t1;
357
 
ERROR HY000: Received an invalid datetime value '0000-00-00'.
 
495
month("0000-00-00")     month(d)        month(dt)       month(t)        month(c)
 
496
0       0       0       0       0
358
497
select quarter("0000-00-00"),quarter(d),quarter(dt),quarter(t),quarter(c) from t1;
359
 
ERROR HY000: Received an invalid datetime value '0000-00-00'.
 
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'
360
506
select year("0000-00-00"),year(d),year(dt),year(t),year(c) from t1;
361
 
ERROR HY000: Received an invalid datetime value '0000-00-00'.
362
 
select to_days("0000-00-00"),to_days(d),to_days(dt),to_days(c) from t1;
363
 
ERROR HY000: Received an invalid datetime value '0000-00-00'.
 
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'
364
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;
365
 
ERROR HY000: Received an invalid datetime value '0000-00-00'.
 
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
366
524
drop table t1;
367
525
CREATE TABLE t1 ( start datetime default NULL);
368
526
INSERT INTO t1 VALUES ('2002-10-21 00:00:00'),('2002-10-28 00:00:00'),('2002-11-04 00:00:00');
382
540
drop table t1,t2,t3;
383
541
select @a:=FROM_UNIXTIME(1);
384
542
@a:=FROM_UNIXTIME(1)
385
 
1970-01-01 00:00:01
 
543
1970-01-01 03:00:01
386
544
select unix_timestamp(@a);
387
545
unix_timestamp(@a)
388
546
1
389
 
select unix_timestamp('1970-01-01 00:00:01');
390
 
unix_timestamp('1970-01-01 00:00:01')
391
 
1
 
547
select unix_timestamp('1969-12-01 19:00:01');
 
548
unix_timestamp('1969-12-01 19:00:01')
 
549
0
392
550
select from_unixtime(-1);
393
551
from_unixtime(-1)
394
552
NULL
395
553
select from_unixtime(2147483647);
396
554
from_unixtime(2147483647)
397
 
2038-01-19 03:14:07
 
555
2038-01-19 06:14:07
398
556
select from_unixtime(2147483648);
399
557
from_unixtime(2147483648)
400
558
NULL
401
559
select from_unixtime(0);
402
560
from_unixtime(0)
403
 
1970-01-01 00:00:00
 
561
1970-01-01 03:00:00
404
562
select unix_timestamp(from_unixtime(2147483647));
405
563
unix_timestamp(from_unixtime(2147483647))
406
564
2147483647
408
566
unix_timestamp(from_unixtime(2147483648))
409
567
NULL
410
568
select unix_timestamp('2039-01-20 01:00:00');
411
 
ERROR HY000: Received an invalid value '2039-01-20 01:00:00' for a UNIX timestamp.
 
569
unix_timestamp('2039-01-20 01:00:00')
 
570
0
412
571
select unix_timestamp('1968-01-20 01:00:00');
413
 
ERROR HY000: Received an invalid value '1968-01-20 01:00:00' for a UNIX timestamp.
 
572
unix_timestamp('1968-01-20 01:00:00')
 
573
0
414
574
select unix_timestamp('2038-02-10 01:00:00');
415
 
ERROR HY000: Received an invalid value '2038-02-10 01:00:00' for a UNIX timestamp.
 
575
unix_timestamp('2038-02-10 01:00:00')
 
576
0
416
577
select unix_timestamp('1969-11-20 01:00:00');
417
 
ERROR HY000: Received an invalid value '1969-11-20 01:00:00' for a UNIX timestamp.
 
578
unix_timestamp('1969-11-20 01:00:00')
 
579
0
418
580
select unix_timestamp('2038-01-20 01:00:00');
419
 
ERROR HY000: Received an invalid value '2038-01-20 01:00:00' for a UNIX timestamp.
 
581
unix_timestamp('2038-01-20 01:00:00')
 
582
0
420
583
select unix_timestamp('1969-12-30 01:00:00');
421
 
ERROR HY000: Received an invalid value '1969-12-30 01:00:00' for a UNIX timestamp.
 
584
unix_timestamp('1969-12-30 01:00:00')
 
585
0
422
586
select unix_timestamp('2038-01-17 12:00:00');
423
587
unix_timestamp('2038-01-17 12:00:00')
424
 
2147342400
425
 
select unix_timestamp('2038-01-19 03:14:07');
426
 
unix_timestamp('2038-01-19 03:14:07')
427
 
2147483647
428
 
CREATE TABLE t1 (datetime datetime, timestamp timestamp, date date);
429
 
INSERT INTO t1 values ("2001-01-02 03:04:05", "2002-01-02 03:04:05", "2003-01-02");
 
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");
430
597
SELECT * from t1;
431
 
datetime        timestamp       date
432
 
2001-01-02 03:04:05     2002-01-02 03:04:05     2003-01-02
 
598
datetime        timestamp       date    time
 
599
2001-01-02 03:04:05     2002-01-02 03:04:05     2003-01-02      06:07:08
433
600
select date_add("1997-12-31",INTERVAL 1 SECOND);
434
601
date_add("1997-12-31",INTERVAL 1 SECOND)
435
602
1997-12-31 00:00:01
499
666
select timestampadd(SQL_TSI_FRAC_SECOND, 1, date) from t1;
500
667
timestampadd(SQL_TSI_FRAC_SECOND, 1, date)
501
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
502
671
select timestampdiff(MONTH, '2001-02-01', '2001-05-01') as a;
503
672
a
504
673
3
532
701
select timestampdiff(SQL_TSI_FRAC_SECOND, '2001-02-01 12:59:59.120000', '2001-05-01 12:58:58.119999') as a;
533
702
a
534
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
535
706
select timestampdiff(SQL_TSI_DAY, '1986-02-01', '1986-03-01') as a1,
536
707
timestampdiff(SQL_TSI_DAY, '1900-02-01', '1900-03-01') as a2,
537
708
timestampdiff(SQL_TSI_DAY, '1996-02-01', '1996-03-01') as a3,
610
781
SELECT TIMESTAMPDIFF(year,'2006-01-10 14:30:28','2008-01-10 14:30:29');
611
782
TIMESTAMPDIFF(year,'2006-01-10 14:30:28','2008-01-10 14:30:29')
612
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
613
789
drop table t1;
614
 
select last_day('2000-02-05');
615
 
last_day('2000-02-05')
616
 
2000-02-29
617
 
select last_day('2002-12-31');
618
 
last_day('2002-12-31')
619
 
2002-12-31
620
 
select last_day('2003-03-32');
621
 
ERROR HY000: Received an invalid datetime value '2003-03-32'.
622
 
select last_day('2003-04-01');
623
 
last_day('2003-04-01')
624
 
2003-04-30
625
 
select last_day('2001-01-01 01:01:01');
626
 
last_day('2001-01-01 01:01:01')
627
 
2001-01-31
628
 
select last_day(NULL);
629
 
last_day(NULL)
630
 
NULL
631
 
select last_day('2001-02-12');
632
 
last_day('2001-02-12')
633
 
2001-02-28
 
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'
634
798
create table t1 select last_day('2000-02-05') as a,
635
799
from_days(to_days("960101")) as b;
636
800
describe t1;
637
 
Field   Type    Null    Default Default_is_NULL On_Update
638
 
a       DATE    NO              NO      
639
 
b       DATE    YES             YES     
 
801
Field   Type    Null    Key     Default Extra
 
802
a       date    NO              0000-00-00      
 
803
b       date    YES             NULL    
640
804
select * from t1;
641
805
a       b
642
806
2000-02-29      1996-01-01
657
821
select last_day("1997-12-1")+0.0;
658
822
last_day("1997-12-1")+0.0
659
823
19971231.0
660
 
select strcmp(date_sub(localtimestamp(), interval 0 hour), utc_timestamp())=0;
661
 
strcmp(date_sub(localtimestamp(), interval 0 hour), utc_timestamp())=0
662
 
1
663
 
select strcmp(date_format(date_sub(localtimestamp(), interval 0 hour),"%Y-%m-%d"), utc_date())=0;
664
 
strcmp(date_format(date_sub(localtimestamp(), interval 0 hour),"%Y-%m-%d"), utc_date())=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
665
835
1
666
836
select strcmp(date_format(utc_timestamp(),"%Y-%m-%d"), utc_date())=0;
667
837
strcmp(date_format(utc_timestamp(),"%Y-%m-%d"), utc_date())=0
668
838
1
669
 
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);
 
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);
670
843
id      select_type     table   type    possible_keys   key     key_len ref     rows    filtered        Extra
671
844
1       SIMPLE  NULL    NULL    NULL    NULL    NULL    NULL    NULL    NULL    No tables used
672
845
Warnings:
673
 
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)`,(weekday(curdate()) - weekday(now())) AS `weekday(curdate())-weekday(now())`,dayname('1962-03-03') AS `dayname("1962-03-03")`,unix_timestamp() AS `unix_timestamp()`,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)`
 
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)`
674
847
SET @TMP='2007-08-01 12:22:49';
675
848
CREATE TABLE t1 (d DATETIME);
676
849
INSERT INTO t1 VALUES ('2007-08-01 12:22:59');
681
854
3
682
855
DROP TABLE t1;
683
856
select last_day('2005-00-00');
684
 
ERROR HY000: Received an invalid datetime value '2005-00-00'.
 
857
last_day('2005-00-00')
 
858
NULL
 
859
Warnings:
 
860
Warning 1292    Incorrect datetime value: '2005-00-00'
685
861
select last_day('2005-00-01');
686
 
ERROR HY000: Received an invalid datetime value '2005-00-01'.
 
862
last_day('2005-00-01')
 
863
NULL
 
864
Warnings:
 
865
Warning 1292    Incorrect datetime value: '2005-00-01'
687
866
select last_day('2005-01-00');
688
 
ERROR HY000: Received an invalid datetime value '2005-01-00'.
689
 
create table t1(f1 date, f3 datetime);
690
 
insert into t1 values ("2006-01-01", "2006-01-01 12:01:01");
691
 
insert into t1 values ("2006-01-02", "2006-01-02 12:01:02");
 
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");
692
885
select f1 from t1 where f1 between CAST("2006-1-1" as date) and CAST(20060101 as date);
693
886
f1
694
887
2006-01-01
698
891
select f1 from t1 where date(f1) between cast("2006-1-1" as date) and cast("2006.1.1" as date);
699
892
f1
700
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
701
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);
702
901
f3
703
902
2006-01-01 12:01:01
714
913
f1
715
914
Warnings:
716
915
Warning 1292    Incorrect datetime value: 'zzz'
 
916
Warning 1292    Incorrect datetime value: 'zzz'
717
917
select f1 from t1 where makedate(2006,1) between date(f1) and date(f3);
718
918
f1
719
919
2006-01-01
721
921
f1
722
922
2006-01-02
723
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'
724
1003
SELECT EXTRACT(HOUR FROM '100000:02:03');
725
 
ERROR HY000: Received an invalid datetime value '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;
726
1024
SHOW VARIABLES LIKE 'character_set_results';
727
1025
Variable_name   Value
728
 
CREATE TABLE testBug8868 (field1 DATE, field2 VARCHAR(32));
 
1026
character_set_results   
 
1027
CREATE TABLE testBug8868 (field1 DATE, field2 VARCHAR(32) CHARACTER SET BINARY);
729
1028
INSERT INTO testBug8868 VALUES ('2006-09-04', 'abcd');
730
1029
SELECT DATE_FORMAT(field1,'%b-%e %l:%i%p') as fmtddate, field2 FROM testBug8868;
731
1030
fmtddate        field2
732
1031
Sep-4 12:00AM   abcd
733
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
734
1063
select last_day('0000-00-00');
735
 
ERROR HY000: Received an invalid datetime value '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
736
1070
End of 4.1 tests
737
1071
explain extended select timestampdiff(SQL_TSI_WEEK, '2001-02-01', '2001-05-01') as a1,
738
1072
timestampdiff(SQL_TSI_FRAC_SECOND, '2001-02-01 12:59:59.120000', '2001-05-01 12:58:58.119999') as a2;
739
1073
id      select_type     table   type    possible_keys   key     key_len ref     rows    filtered        Extra
740
1074
1       SIMPLE  NULL    NULL    NULL    NULL    NULL    NULL    NULL    NULL    No tables used
741
1075
Warnings:
 
1076
Warning 1287    The syntax 'FRAC_SECOND' is deprecated and will be removed in MySQL 6.2. Please use MICROSECOND instead
742
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`
743
1078
select time_format('100:00:00', '%H %k %h %I %l');
744
1079
time_format('100:00:00', '%H %k %h %I %l')
745
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;
746
1124
select timestampdiff(month,'2004-09-11','2004-09-11');
747
1125
timestampdiff(month,'2004-09-11','2004-09-11')
748
1126
0
805
1183
'2005.09.01' - INTERVAL 6 MONTH AND t2.day;
806
1184
id      day     id      day
807
1185
1       2005-06-01      1       2005-08-01
 
1186
3       2005-07-01      1       2005-08-01
808
1187
1       2005-06-01      2       2005-06-15
809
1188
1       2005-06-01      3       2005-07-15
810
 
3       2005-07-01      1       2005-08-01
811
1189
3       2005-07-01      3       2005-07-15
812
1190
SELECT * FROM t1, t2 
813
1191
WHERE CAST(t1.day AS DATE) BETWEEN 
814
1192
'2005.09.01' - INTERVAL 6 MONTH AND t2.day;
815
1193
id      day     id      day
816
1194
1       2005-06-01      1       2005-08-01
 
1195
3       2005-07-01      1       2005-08-01
817
1196
1       2005-06-01      2       2005-06-15
818
1197
1       2005-06-01      3       2005-07-15
819
 
3       2005-07-01      1       2005-08-01
820
1198
3       2005-07-01      3       2005-07-15
821
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
822
1204
create table t1 (field DATE);
823
1205
insert into t1 values ('2006-11-06');
824
1206
select * from t1 where field < '2006-11-06 04:08:36.0';
836
1218
field
837
1219
2006-11-06
838
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;
839
1254
select DATE_ADD('20071108181000', INTERVAL 1 DAY);
840
1255
DATE_ADD('20071108181000', INTERVAL 1 DAY)
841
1256
2007-11-09 18:10:00
854
1269
SELECT TIMESTAMPADD(FRAC_SECOND, 1, '2008-02-18');
855
1270
TIMESTAMPADD(FRAC_SECOND, 1, '2008-02-18')
856
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
857
1274
SELECT TIMESTAMPDIFF(FRAC_SECOND, '2008-02-17', '2008-02-18');
858
1275
TIMESTAMPDIFF(FRAC_SECOND, '2008-02-17', '2008-02-18')
859
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
860
1279
SELECT DATE_ADD('2008-02-18', INTERVAL 1 FRAC_SECOND);
861
 
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your Drizzle server version for the right syntax to use near 'FRAC_SECOND)' at line 1
 
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
862
1281
SELECT DATE_SUB('2008-02-18', INTERVAL 1 FRAC_SECOND);
863
 
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your Drizzle server version for the right syntax to use near 'FRAC_SECOND)' at line 1
 
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
864
1283
SELECT '2008-02-18' + INTERVAL 1 FRAC_SECOND;
865
 
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your Drizzle server version for the right syntax to use near 'FRAC_SECOND' at line 1
 
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
866
1285
SELECT '2008-02-18' - INTERVAL 1 FRAC_SECOND;
867
 
ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your Drizzle server version for the right syntax to use near 'FRAC_SECOND' at line 1
 
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
868
1287
End of 5.0 tests
869
1288
select date_sub("0050-01-01 00:00:01",INTERVAL 2 SECOND);
870
1289
date_sub("0050-01-01 00:00:01",INTERVAL 2 SECOND)