Mysql详细介绍日期和时间函数
2007-11-13 11:04:04 来源:WEB开发网包含YEAR、MONTH和DAY部分(即,没有时间部分),结果是一个DATE值。否则结果是一个DATETIME值。
mysql>Select"1997-12-3123:59:59"+INTERVAL1SECOND;
->1998-01-0100:00:00
mysql>SelectINTERVAL1DAY+"1997-12-31";
->1998-01-01
mysql>Select"1998-01-01"-INTERVAL1SECOND;
->1997-12-3123:59:59
mysql>SelectDATE_ADD("1997-12-3123:59:59",
INTERVAL1SECOND);
->1998-01-0100:00:00
mysql>SelectDATE_ADD("1997-12-3123:59:59",
INTERVAL1DAY);
->1998-01-0123:59:59
mysql>SelectDATE_ADD("1997-12-3123:59:59",
INTERVAL"1:1"MINUTE_SECOND);
->1998-01-0100:01:00
mysql>SelectDATE_SUB("1998-01-0100:00:00",
INTERVAL"11:1:1"DAY_SECOND);
->1997-12-3022:58:59
mysql>SelectDATE_ADD("1998-01-0100:00:00",
INTERVAL"-110"DAY_HOUR);
->1997-12-3014:00:00
mysql>SelectDATE_SUB("1998-01-02",INTERVAL31DAY);
->1997-12-02
mysql>SelectEXTRACT(YEARFROM"1999-07-02");
->1999
mysql>SelectEXTRACT(YEAR_MONTHFROM"1999-07-0201:02:03");
->199907
mysql>SelectEXTRACT(DAY_MINUTEFROM"1999-07-0201:02:03");
->20102
更多精彩
赞助商链接