我的表中有一个时间戳值,它表示生成记录的时间。
我想找出使用 MySQL 生成记录之前的秒数、小时数、天数。换句话说,我们如何从 MySQL 中的当前时间和时间戳值中找出以秒、小时、日格式表示的时间差异?
试试这个
SELECT TIMESTAMPDIFF (SECOND, CURDATE(), your_timestamp_field) from your_table;
有关更多信息,请参阅日期和时间函数
> SELECT A.CALLSIGN,TO_CHAR(A.TIMEOFMSGRCVD ,'YYYYMMDDHH24MISS')
> time_tmo,TO_CHAR(b.TIMEOFMSGRCVD ,'YYYYMMDDHH24MISS') time_arrival,
> floor(((b.TIMEOFMSGRCVD-a.TIMEOFMSGRCVD)*24*60*60)/3600)
> HOURS,
> floor((((b.TIMEOFMSGRCVD-a.TIMEOFMSGRCVD)*24*60*60) -
> floor(((b.TIMEOFMSGRCVD-a.TIMEOFMSGRCVD)*24*60*60)/3600)*3600)/60)
> MINUTES,
> round((((b.TIMEOFMSGRCVD-a.TIMEOFMSGRCVD)*24*60*60) -
> floor(((b.TIMEOFMSGRCVD-a.TIMEOFMSGRCVD)*24*60*60)/3600)*3600 -
> (floor((((b.TIMEOFMSGRCVD-a.TIMEOFMSGRCVD)*24*60*60) -
> floor(((b.TIMEOFMSGRCVD-a.TIMEOFMSGRCVD)*24*60*60)/3600)*3600)/60)*60)
> ))
> SECONDS FROM (SELECT * FROM ATC.ATCMSG WHERE FLIGHTDATE=TO_CHAR(SYSDATE-1,'MMDDYY') AND EVENTTYPE='DES') a, (SELECT
> * FROM ATC.ATCMSG WHERE FLIGHTDATE=TO_CHAR(SYSDATE-1,'MMDDYY') AND EVENTTYPE='ARR') b WHERE A.CALLSIGN=B.CALLSIGN ORDER BY 4,5,6;