Home » Infrastructure » Unix » DATE - DATE
DATE - DATE [message #97914] Wed, 28 May 2003 08:19 Go to next message
Milan
Messages: 7
Registered: February 1999
Junior Member
Hi!

I need anything as :

SELECT (END_TIME - START_TIME) AS REAL_TIME FROM DUAL

But I need the REAL_TIME in format : "1 yer, 6 months, 3 days, 8 hours, 10 minutes, 5 seconds"

can you help me ?
Re: DATE - DATE [message #97921 is a reply to message #97914] Tue, 03 June 2003 16:16 Go to previous messageGo to next message
Art Metzer
Messages: 2480
Registered: December 2002
Senior Member
You asked for it.
SQL> SELECT TO_CHAR(start_time
  2         ,       'fmDy MM/DD/YYYY HH12:fmMI:SS AM') start_time
  3  ,      TO_CHAR(end_time
  4         ,       'fmDy MM/DD/YYYY HH12:fmMI:SS AM') end_time
  5  ,      DECODE(TRUNC(MONTHS_BETWEEN(end_time,start_time) / 12)
  6         ,      0, NULL
  7         ,      1, '1 year, '
  8         ,      TRUNC(MONTHS_BETWEEN(end_time,start_time) / 12)
  9                || ' years, ')
 10  ||     DECODE(TRUNC(MOD(MONTHS_BETWEEN(end_time,start_time),12))
 11         ,      0, NULL
 12         ,      1, '1 month, '
 13         ,      TRUNC(MOD(MONTHS_BETWEEN(end_time,start_time),12))
 14                || ' months, ')
 15  ||     DECODE(TRUNC(end_time) - ADD_MONTHS(TRUNC(start_time)
 16                                  ,          TRUNC(MONTHS_BETWEEN(end_time 
 17                                                   ,              start_time)))
 18         ,      0, NULL
 19         ,      1, '1 day, '
 20         ,      TRUNC(end_time) - ADD_MONTHS(TRUNC(start_time)
 21                                  ,          TRUNC(MONTHS_BETWEEN(end_time 
 22                                                   ,              start_time)))
 23                || ' days, ')
 24  ||     DECODE(TRUNC(MOD(diff_in_secs / 60 / 60, 24))
 25         ,      0, NULL
 26         ,      1, '1 hour, '
 27         ,      TRUNC(MOD(diff_in_secs / 60 / 60, 24))
 28                || ' hours, ')
 29  ||     DECODE(TRUNC(MOD(diff_in_secs / 60, 60))
 30         ,      0, NULL
 31         ,      1, '1 minute, '
 32         ,      TRUNC(MOD(diff_in_secs / 60, 60))
 33                || ' minutes, ')       
 34  ||     DECODE(ROUND(MOD(diff_in_secs, 60))
 35         ,      0, NULL
 36         ,      1, '1 second'
 37         ,      ROUND(MOD(diff_in_secs, 60))
 38                || ' seconds') real_time
 39  FROM (SELECT start_time
 40        ,      end_time
 41        ,    ((end_time - start_time) * 24 * 60 * 60) diff_in_secs
 42        FROM  (SELECT TO_DATE('20000101'
 43                      ,       'YYYYMMDD')             start_time
 44  ,                   TO_DATE('20081230235959'
 45                      ,       'YYYYMMDDHH24MISS')     end_time
 46               FROM DUAL))
 47  /
  
START_TIME               END_TIME                   REAL_TIME
------------------------ -------------------------- -------------------------------------------------------------
Sat 1/1/2000 12:00:00 AM Tue 12/30/2008 11:59:59 PM 8 years, 11 months, 29 days, 23 hours, 59 minutes, 59 seconds
  
SQL> 
HTH,

A
Re: DATE - DATE [message #97922 is a reply to message #97914] Tue, 03 June 2003 23:54 Go to previous messageGo to next message
Milan
Messages: 7
Registered: February 1999
Junior Member
Thank you very much
Re: DATE - DATE [message #98069 is a reply to message #97921] Sun, 18 January 2004 18:33 Go to previous messageGo to next message
resy
Messages: 86
Registered: December 2003
Member
thanx alot.
Re: DATE - DATE [message #133795 is a reply to message #97914] Mon, 22 August 2005 04:58 Go to previous message
bhagwan
Messages: 86
Registered: September 2004
Member
This query gives a blank column if start_time and end_time happen to be on same day.

Can you please check Art?
Previous Topic: sed .. inserts newline and spaces...
Next Topic: X server problem & creating a second database on HP-UX
Goto Forum:
  


Current Time: Mon Nov 25 21:45:01 CST 2024