select unix_timestamp();
获取当前时间的时间戳SELECT FROM_UNIXTIME(1529999834);
时间戳转换为北京时间要得到正确的时间相减秒值
time_to_sec(timediff(t2, t1)),
timestampdiff(second, t1, t2),
unix_timestamp(t2) -unix_timestamp(t1)
SELECT AcceptTime,CreateTime, (AcceptTime-CreateTime) sec FROM `req_dlr` WHERE SellOrg="CC经销商88" AND CreateTime>="1527350400" AND CreateTime <= "1529942399" AND AcceptTime <>"0" AND makeid = "36000000" AND ReqState <> "97";
此时用第3种方法,时间戳直接相减
3、timediff(time1,time2),两个时间相减,返回time差值,如图
注意:timediff(time1,time2) 函数的两个参数类型必须相同。
3.1、
MySQL (时间和秒互相转换):time_to_sec(time), sec_to_time(seconds)
select time_to_sec("01:00:05"); -- 3605 转换为秒 select sec_to_time(3605); -- "01:00:05"
3.2、
1、req_dlr表中AcceptTime,CreateTime两个时间戳转换为北京时间,然后只取时间
2、把取到的时间转换为秒,相减后求和
SELECT sum(time_to_sec(M.A)- TIME_TO_SEC(M.C)) FROM ( SELECT date_format( FROM_UNIXTIME(AcceptTime), "%H:%i:%S" ) A, date_format( FROM_UNIXTIME(CreateTime), "%H:%i:%S" ) C FROM `req_dlr` WHERE CreateTime >= "1527350400" AND CreateTime <= "1529942399" AND AcceptTime <> "0" AND makeid = "36000000" AND ReqState <> "97" ) AS M WHERE M.A <= "19:00:00" AND M.A >= "09:00:00";
以上为个人经验,希望能给大家一个参考,也希望大家多多支持。