# # time functions # drop table if exists t1,t2; 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"); select period_add("9602",-12),period_diff(199505,"9404") ; select now()-now(),weekday(curdate())-weekday(now()),unix_timestamp()-unix_timestamp(now()); 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; select sec_to_time(9001),sec_to_time(9001)+0,time_to_sec("15:12:22"); select now()-curdate()*1000000-curtime(); select strcmp(current_timestamp(),concat(current_date()," ",current_time())); select date_format("1997-01-02 03:04:05", "%M %W %D %Y %y %m %d %h %i %s %w"); select date_format("1997-01-02", concat("%M %W %D ","%Y %y %m %d %h %i %s %w")); select dayofmonth("1997-01-02"),dayofmonth(19970323); select month("1997-01-02"),year("98-02-03"),dayofyear("1997-12-31"); select month("2001-02-00"),year("2001-00-00"); select DAYOFYEAR("1997-03-03"), WEEK("1998-03-03"), QUARTER(980303); select HOUR("1997-03-03 23:03:22"), MINUTE("23:03:22"), SECOND(230322); select week(19980101),week(19970101),week(19980101,1),week(19970101,1); select week(19981231),week(19971231),week(19981231,1),week(19971231,1); select week(19950101),week(19950101,1); select yearweek('1981-12-31',1),yearweek('1982-01-01',1),yearweek('1982-12-31',1),yearweek('1983-01-01',1); select date_format('1998-12-31','%x-%v'),date_format('1999-01-01','%x-%v'); select date_format('1999-12-31','%x-%v'),date_format('2000-01-01','%x-%v'); select yearweek('1987-01-01',1),yearweek('1987-01-01'); select dayname("1962-03-03"),dayname("1962-03-03")+0; select monthname("1972-03-04"),monthname("1972-03-04")+0; select time_format(19980131000000,'%H|%I|%k|%l|%i|%p|%r|%S|%T'); select time_format(19980131010203,'%H|%I|%k|%l|%i|%p|%r|%S|%T'); select time_format(19980131131415,'%H|%I|%k|%l|%i|%p|%r|%S|%T'); select time_format(19980131010015,'%H|%I|%k|%l|%i|%p|%r|%S|%T'); select date_format(concat('19980131',131415),'%H|%I|%k|%l|%i|%p|%r|%S|%T| %M|%W|%D|%Y|%y|%a|%b|%j|%m|%d|%h|%s|%w'); select date_format(19980021000000,'%H|%I|%k|%l|%i|%p|%r|%S|%T| %M|%W|%D|%Y|%y|%a|%b|%j|%m|%d|%h|%s|%w'); select date_add("1997-12-31 23:59:59",INTERVAL 1 SECOND); select date_add("1997-12-31 23:59:59",INTERVAL 1 MINUTE); select date_add("1997-12-31 23:59:59",INTERVAL 1 HOUR); select date_add("1997-12-31 23:59:59",INTERVAL 1 DAY); select date_add("1997-12-31 23:59:59",INTERVAL 1 MONTH); select date_add("1997-12-31 23:59:59",INTERVAL 1 YEAR); select date_add("1997-12-31 23:59:59",INTERVAL "1:1" MINUTE_SECOND); select date_add("1997-12-31 23:59:59",INTERVAL "1:1" HOUR_MINUTE); select date_add("1997-12-31 23:59:59",INTERVAL "1:1" DAY_HOUR); select date_add("1997-12-31 23:59:59",INTERVAL "1 1" YEAR_MONTH); select date_add("1997-12-31 23:59:59",INTERVAL "1:1:1" HOUR_SECOND); select date_add("1997-12-31 23:59:59",INTERVAL "1 1:1" DAY_MINUTE); select date_add("1997-12-31 23:59:59",INTERVAL "1 1:1:1" DAY_SECOND); select date_sub("1998-01-01 00:00:00",INTERVAL 1 SECOND); select date_sub("1998-01-01 00:00:00",INTERVAL 1 MINUTE); select date_sub("1998-01-01 00:00:00",INTERVAL 1 HOUR); select date_sub("1998-01-01 00:00:00",INTERVAL 1 DAY); select date_sub("1998-01-01 00:00:00",INTERVAL 1 MONTH); select date_sub("1998-01-01 00:00:00",INTERVAL 1 YEAR); select date_sub("1998-01-01 00:00:00",INTERVAL "1:1" MINUTE_SECOND); select date_sub("1998-01-01 00:00:00",INTERVAL "1:1" HOUR_MINUTE); select date_sub("1998-01-01 00:00:00",INTERVAL "1:1" DAY_HOUR); select date_sub("1998-01-01 00:00:00",INTERVAL "1 1" YEAR_MONTH); select date_sub("1998-01-01 00:00:00",INTERVAL "1:1:1" HOUR_SECOND); select date_sub("1998-01-01 00:00:00",INTERVAL "1 1:1" DAY_MINUTE); select date_sub("1998-01-01 00:00:00",INTERVAL "1 1:1:1" DAY_SECOND); select date_add("1997-12-31 23:59:59",INTERVAL 100000 SECOND); select date_add("1997-12-31 23:59:59",INTERVAL -100000 MINUTE); select date_add("1997-12-31 23:59:59",INTERVAL 100000 HOUR); select date_add("1997-12-31 23:59:59",INTERVAL -100000 DAY); select date_add("1997-12-31 23:59:59",INTERVAL 100000 MONTH); select date_add("1997-12-31 23:59:59",INTERVAL -100000 YEAR); select date_add("1997-12-31 23:59:59",INTERVAL "10000:1" MINUTE_SECOND); select date_add("1997-12-31 23:59:59",INTERVAL "-10000:1" HOUR_MINUTE); select date_add("1997-12-31 23:59:59",INTERVAL "10000:1" DAY_HOUR); select date_add("1997-12-31 23:59:59",INTERVAL "-100 1" YEAR_MONTH); select date_add("1997-12-31 23:59:59",INTERVAL "10000:99:99" HOUR_SECOND); select date_add("1997-12-31 23:59:59",INTERVAL " -10000 99:99" DAY_MINUTE); select date_add("1997-12-31 23:59:59",INTERVAL "10000 99:99:99" DAY_SECOND); select "1997-12-31 23:59:59" + INTERVAL 1 SECOND; select INTERVAL 1 DAY + "1997-12-31"; select "1998-01-01 00:00:00" - INTERVAL 1 SECOND; select date_sub("1998-01-02",INTERVAL 31 DAY); select date_add("1997-12-31",INTERVAL 1 SECOND); select date_add("1997-12-31",INTERVAL 1 DAY); select date_add(NULL,INTERVAL 100000 SECOND); select date_add("1997-12-31 23:59:59",INTERVAL NULL SECOND); select date_add("1997-12-31 23:59:59",INTERVAL NULL MINUTE_SECOND); select date_add("9999-12-31 23:59:59",INTERVAL 1 SECOND); select date_sub("0000-00-00 00:00:00",INTERVAL 1 SECOND); select date_add('1998-01-30',Interval 1 month); select date_add('1998-01-30',Interval '2:1' year_month); select date_add('1996-02-29',Interval '1' year); select extract(YEAR FROM "1999-01-02 10:11:12"); select extract(YEAR_MONTH FROM "1999-01-02"); select extract(DAY FROM "1999-01-02"); select extract(DAY_HOUR FROM "1999-01-02 10:11:12"); select extract(DAY_MINUTE FROM "02 10:11:12"); select extract(DAY_SECOND FROM "225 10:11:12"); select extract(HOUR FROM "1999-01-02 10:11:12"); select extract(HOUR_MINUTE FROM "10:11:12"); select extract(HOUR_SECOND FROM "10:11:12"); select extract(MINUTE FROM "10:11:12"); select extract(MINUTE_SECOND FROM "10:11:12"); select extract(SECOND FROM "1999-01-02 10:11:12"); select extract(MONTH FROM "2001-02-00"); create table t1 (ctime varchar(20)); insert into t1 values ('2001-01-12 12:23:40'); select ctime, hour(ctime) from t1; drop table t1; # # Test bug with monthname() and NULL # create table t1 (id int); create table t2 (id int, date date); insert into t1 values (1); insert into t2 values (1, "0000-00-00"); insert into t1 values (2); insert into t2 values (2, "2000-01-01"); select monthname(date) from t1 inner join t2 on t1.id = t2.id; select monthname(date) from t1 inner join t2 on t1.id = t2.id order by t1.id; drop table t1,t2; # # Test bug with month() and year() on text fields with wrong information CREATE TABLE t1 (updated text) TYPE=MyISAM; INSERT INTO t1 VALUES (''); SELECT month(updated) from t1; SELECT year(updated) from t1; drop table t1;