我的表中有一个时间戳值,表示记录生成的时间。
我想知道使用MySQL生成记录之前的秒数,小时数和天数。换句话说,我们怎样才能找出MySQL,当前时间和时间戳值的秒,小时,日格式的时间差异?
答案 0 :(得分:0)
试试这个
SELECT TIMESTAMPDIFF (SECOND, CURDATE(), your_timestamp_field) from your_table;
有关详细信息,请参阅date and time functions
答案 1 :(得分:-1)
> 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;