Results 1 to 3 of 3

Thread: date difference

  1. #1
    Join Date
    Sep 2003
    Posts
    1

    Unanswered: date difference

    how to find out the difference in 2 dates , i have date1 and date2 and have to caluclate how many days is the difference

  2. #2
    Join Date
    Sep 2003
    Location
    Assen, Nederland
    Posts
    55
    an example...

    Code:
    Connected to:
    Oracle8i Enterprise Edition Release 8.1.7.4.1 - Production
    With the Partitioning option
    JServer Release 8.1.7.4.1 - Production
    
    
    SQL> create table t1
      2  (date1 date,
      3  date2 date)
      4  /
    
    Table created.
    
    SQL> insert into t1
      2  values ('01-JAN-2003','29-SEP-2003')
      3  /
    
    1 row created.
    
    SQL> SELECT MONTHS_BETWEEN (date2, date1),
      2         TRUNC (MONTHS_BETWEEN (date2, date1) / 12) years,
      3         MOD (TRUNC (MONTHS_BETWEEN (date2, date1)), 12) months,
      4         date2 - ADD_MONTHS (date1, TRUNC (MONTHS_BETWEEN (date2, date1))) days
      5    FROM t1
      6  /
    
    MONTHS_BETWEEN(DATE2,DATE1)      YEARS     MONTHS       DAYS
    --------------------------- ---------- ---------- ----------
                     8.90322581          0          8         28

    Cheers...
    Hope that helped...
    Visit My Website : http://www.oraflame.com
    _____________________________
    Tarry Singh

    OCP DBA 8i
    Currently: SQL Server DBA 7,2000
    Oracle, PHP Programmer

  3. #3
    Join Date
    Sep 2003
    Location
    The Netherlands
    Posts
    311
    hi,

    if you only want the number of days try :

    select trunc(to_date('01-03-2003','DD-MM-YYYY')) - trunc(to_date('01-02-2003','DD-MM-YYYY')) from dual;

    Hope this helps
    Edwin van Hattem
    OCP DBA / System analyst

Posting Permissions

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