Results 1 to 4 of 4

Thread: Date Difference

  1. #1
    Join Date
    Jan 2004
    Posts
    2

    Unanswered: Date Difference

    I have a Oracle Table with Start_Time & End_Time in it.

    I want to know a SQL Query to find the difference in Years,Months,Weeks,Days,Hours,Minutes & Seconds between the above 2 values.

  2. #2
    Join Date
    Nov 2003
    Posts
    87

  3. #3
    Join Date
    Nov 2003
    Posts
    87
    hi,
    hope this will help you


    SQL> desc test_dates
    Name Null? Type
    ----------------------------------------- -------- ----------------------------
    D1 DATE
    D2 DATE

    SQL> SELECT TO_CHAR(d1,'DD-MON-YYYY HH24:MIS') AS d1 , TO_CHAR(d2,'DD-MON-YYYY HH24:MIS') AS
    d2 , TRUNC(MONTHS_BETWEEN(d2, d1)/12) AS years , MOD(TRUNC(MONTHS_BETWEEN(d2, d1)),12) AS m
    onths , TRUNC(ADD_MONTHS(d2, TRUNC(MONTHS_BETWEEN(d2, d1)) * -1) -d1) AS days , TO_CHAR(TRUN
    C(SYSDATE) + ABS(MOD(d2 - d1, 1)), 'HH24:MIS') AS time FROm test_dates
    2 /

    D1 D2 YEARS MONTHS DAYS TIME-------------------- -------------------- ---------- ---------- ---------- --------14-JUL-1789 00:00:00 17-JAN-2004 19:01:53 214 6 3 19:01:5306-SEP-1998 00:00:00 31-AUG-2000 19:02:43 1 11 24 19:02:4317-JAN-2004 19:03:30 17-JAN-2004 08:41:17 0 0 0 10:22:13

  4. #4
    Join Date
    Jan 2004
    Posts
    2

    Thank Q

    Thank a lot Raseena

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •