Home > Database > Mysql Tutorial > MySQL中TIMESTAMPDIFF和TIMESTAMPADD函数的用法_MySQL

MySQL中TIMESTAMPDIFF和TIMESTAMPADD函数的用法_MySQL

WBOY
Release: 2016-06-01 13:40:42
Original
1027 people have browsed it

bitsCN.com
MySQL中TIMESTAMPDIFF和TIMESTAMPADD函数的用法 在应用时,经常要使用这两个函数TIMESTAMPDIFF和TIMESTAMPADD。 一,TIMESTAMPDIFF语法:TIMESTAMPDIFF(interval,datetime_expr1,datetime_expr2)。 说明:   返回日期或日期时间表达式datetime_expr1 和datetime_expr2the 之间的整数差。其结果的单位由interval 参数给出。该参数必须是以下值的其中一个: FRAC_SECOND。表示间隔是毫秒SECOND。秒MINUTE。分钟HOUR。小时DAY。天WEEK。星期MONTH。月QUARTER。季度YEAR。年
 使用如下:[sql] mysql> select TIMESTAMPDIFF(day,'2012-08-24','2012-08-30');  +----------------------------------------------+  | TIMESTAMPDIFF(day,'2012-08-24','2012-08-30') |  +----------------------------------------------+  |                                            6 |   +----------------------------------------------+  1 row in set (0.00 sec)     [sql] mysql> select TIMESTAMPDIFF(MINUTE,'2012-08-24 09:00:00','2012-08-30 12:00:00');  +-------------------------------------------------------------------+  | TIMESTAMPDIFF(MINUTE,'2012-08-24 09:00:00','2012-08-30 12:00:00') |  +-------------------------------------------------------------------+  |                                                              8820 |   +-------------------------------------------------------------------+  1 row in set (0.01 sec)   二,TIMESTAMPADD语法:TIMESTAMPADD(interval,int_expr,datetime_expr)   说明:将整型表达式int_expr 添加到日期或日期时间表达式 datetime_expr中。式中的interval和上文中列举的取值是一样的。
 [sql] mysql> select TIMESTAMPADD(MINUTE,8820,'2012-08-24 09:00:00');  +-------------------------------------------------+  | TIMESTAMPADD(MINUTE,8820,'2012-08-24 09:00:00') |  +-------------------------------------------------+  | 2012-08-30 12:00:00                             |   +-------------------------------------------------+  1 row in set (0.00 sec)   bitsCN.com

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template