Results 1 to 3 of 3
  1. #1
    Join Date
    Jun 2009
    Posts
    46

    Unanswered: Difference between two dates

    Hi,

    I have two date field and i want to take the difference between both date fields in year and month,
    i.e. date1 = 01-01-2008(dd/mm/yyyy)
    date2 = 01-02-2009(dd/mm/yyyy)
    then DiffDate = 1 year and 1 Month.

    Regard's

    Prasad

  2. #2
    Join Date
    Mar 2007
    Posts
    623
    have a look at MONTHS_BETWEEN function.
    Code:
    SQL> select months_between( to_date( '01/02/2009','dd/mm/yyyy' ), 
      2                         to_date( '01/01/2008','dd/mm/yyyy' ) ) diff
      3  from dual;
    
          DIFF
    ----------
            13
    
    1 row selected.
    
    SQL>
    As one year has always 12 months, the rest is simple mathematics.

  3. #3
    Join Date
    Jan 2004
    Location
    Croatia, Europe
    Posts
    4,094
    Provided Answers: 4
    Or, subtract two dates:
    Code:
    SQL> select to_date('01.02.2009', 'dd.mm.yyyy') - to_date('01.01.2008', 'dd.mm.yyyy') result
      2  from dual;
    
        RESULT
    ----------
           397
    
    SQL>
    The result is number of days.

Posting Permissions

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