#两日期/时间之间相差的天数:
To_Days(end_time)-To_Days(start_time) #两日期/时间之间相差的秒数: SELECT UNIX_TIMESTAMP(end_time)- UNIX_TIMESTAMP(start_time); #两日期/时间之间相差的时分数: SELECT SEC_TO_TIME(UNIX_TIMESTAMP(end_time)- UNIX_TIMESTAMP(start_time));最好的办法是直接用“+”,“-” 计算,目前的版本都支持了。比如:SELECT * FROM Table_Name WHERE loginDate < NOW() -10 * 60;实例:
SELECT SEC_TO_TIME(UNIX_TIMESTAMP((SELECT createdtime FROM `Z_2015-09-15` WHERE deviceid='460040271516782' order by id DESC limit 1)) - UNIX_TIMESTAMP((SELECT createdtime FROM `Z_2015-09-15` WHERE deviceid='460040271516782' limit 1)));