MySQL:
SET @a:=UNIX_TIMESTAMP(NOW()) - UNIX_TIMESTAMP(CURRENT_DATE());
SELECT CONCAT(IF(TRUNCATE(@a/24/3600,0)=0,'',CONCAT(TRUNCATE(@a/24/3600,0),'天')),
IF(MOD(TRUNCATE(@a/3600,0),24)=0,'',CONCAT(MOD(TRUNCATE(@a/3600,0),24),'小时')),
IF(MOD(TRUNCATE(@a/60,0),60)=0,'',CONCAT(MOD(TRUNCATE(@a/60,0),60),'分')),
IF(MOD(@a,60)=0,'',CONCAT(MOD(@a,60),'秒'))) dt_diff;
Oracle:
WITH a
AS (SELECT SYSDATE - TRUNC(SYSDATE) tt
FROM DUAL)
SELECT DECODE (TRUNC (tt, 0), 0, NULL, TRUNC (tt, 0) || '天')
|| DECODE (TRUNC (MOD (tt, 1) * 24, 0),
0, NULL,
TRUNC (MOD (tt, 1) * 24, 0) || '小时')
|| DECODE (TRUNC (MOD (tt * 24, 1) * 60, 0),
0, NULL,
TRUNC (MOD (tt * 24, 1) * 60, 0) || '分')
|| DECODE (ROUND (MOD (tt * 24 * 60, 1) * 60, 0),
0, NULL,
ROUND (MOD (tt * 24 * 60, 1) * 60, 0) || '秒')
--转自