亲宝软件园·资讯

展开

mysql中TIMESTAMPDIFF mysql中TIMESTAMPDIFF案例详解

baiyaoliang7445 人气:0
想了解mysql中TIMESTAMPDIFF案例详解的相关内容吗,baiyaoliang7445在本文为您仔细讲解mysql中TIMESTAMPDIFF的相关知识和一些Code实例,欢迎阅读和指正,我们先划重点:mysql中TIMESTAMPDIFF,mysql中TIMESTAMPDIFF讲解,下面大家一起来学习吧。

1.  Syntax

TIMESTAMPDIFF(unit,begin,end); 根据单位返回时间差,对于传入的begin和end不需要相同的数据结构,可以存在一个为Date一个DateTime

2. Unit

支持的单位有

3. Example

下面这个例子是对于TIMESTAMPDIFF最基本的用法,

SELECT TIMESTAMPDIFF(MONTH, '2017-01-01', '2017-02-01') as  result;

+--------+
| result |
+--------+
| 1 |
+--------+
1 row in set (0.00 sec)
SELECT TIMESTAMPDIFF(DAY, '2017-01-01', '2017-02-01') as  result;

+--------+
| result |
+--------+
| 31 |
+--------+
1 row in set (0.00 sec)
SELECT TIMESTAMPDIFF(MINUTE, '2017-01-01 08:00:00', '2017-01-01 08:55:00') result;

+--------+
| result |
+--------+
| 55 |
+--------+
1 row in set (0.00 sec)
SELECT TIMESTAMPDIFF(MINUTE, '2017-01-01 08:00:00', '2017-01-01 08:55:33') result;

+--------+
| result |
+--------+
| 55 |
+--------+
1 row in set (0.00 sec)

SELECT TIMESTAMPDIFF(SECOND, '2017-01-01 08:00:00', '2017-01-01 08:55:33') result;

55 * 60 + 33 = 3333
+--------+
| result |
+--------+
|   3333 |
+--------+
1 row in set (0.00 sec)

加载全部内容

相关教程
猜你喜欢
用户评论