mysql 时间 秒数,mysql计算每天两个日期/时间之间的秒数

I have this table but I am helpless how to calculate seconds for each separate day from this table:

id from to

---------------------------------------------------

1 2013-01-31 23:50:00 2013-02-02 09:00:00

2 2013-02-05 11:21:12 2013-02-08 01:01:01

3 2013-02-08 17:33:44 2013-02-08 18:22:55

4 2013-02-12 01:40:12 2013-02-12 02:00:59

5 2013-02-28 01:40:12 2013-03-02 02:00:59

Now I need to gain number of seconds for each day in february between from and to.

so for 1st Feb - x seconds, 2nd Feb - y seconds, 3rd Feb - 0 seconds, etc. Any idea how should I do it? Many thanks.

解决方案SELECT TIMESTAMPDIFF(SECOND,from,to);

Example:

SELECT TIMESTAMPDIFF(SECOND,'2016-01-01 00:00:00','2016-01-11 00:00:00'); -- 864000

SELECT TIMESTAMPDIFF(MINUTE,'2016-01-01 00:00:00','2016-01-11 00:00:00'); -- 14400

SELECT TIMESTAMPDIFF(HOUR,'2016-01-01 00:00:00','2016-01-11 00:00:00'); -- 240

SELECT TIMESTAMPDIFF(DAY,'2016-01-01 00:00:00','2016-01-11 00:00:00'); -- 10

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值