Results 1 to 3 of 3
  1. #1
    Join Date
    Oct 2003
    Posts
    3

    Unanswered: Adding years in Oracle

    Hello,

    Does anyone know how to add years in Oracle. I don't want to add 365 days, because it doesn't take into account leap years.

    Thanks in advance,

  2. #2
    Join Date
    Jul 2003
    Posts
    2,296
    my book says you can add months.

    look! it worked!
    PHP Code:
    17:29:40 kod:integrationselect add_months(sysdate,24new_date
    17
    :30:09   2  from dual;

    NEW_DATE
    ---------
    22-DEC-05

    Elapsed
    00:00:00.00
    17
    :30:09 kod:integration
    doesn't account for leapyear though, it just adds months.
    If you add days it would account for leap years I believe.

    here are some more tests.
    See hoe the date changes when I add 5 years in days instead of months?
    PHP Code:
    17:33:14 kod:integrationselect add_months(sysdate,60from dual;

    ADD_MONTH
    ---------
    22-DEC-08

    Elapsed
    00:00:00.00
    17
    :35:59 kod:integrationselect sysdate+1825 from dual;

    SYSDATE+1
    ---------
    20-DEC-08

    Elapsed
    00:00:00.00
    17
    :36:07 kod:integration
    - The_Duck
    you can lead someone to something but they will never learn anything ...

  3. #3
    Join Date
    Oct 2003
    Posts
    3
    Thank you.

    Originally posted by The_Duck
    my book says you can add months.

    look! it worked!
    PHP Code:
    17:29:40 kod:integrationselect add_months(sysdate,24new_date
    17
    :30:09   2  from dual;

    NEW_DATE
    ---------
    22-DEC-05

    Elapsed
    00:00:00.00
    17
    :30:09 kod:integration
    doesn't account for leapyear though, it just adds months.
    If you add days it would account for leap years I believe.

    here are some more tests.
    See hoe the date changes when I add 5 years in days instead of months?
    PHP Code:
    17:33:14 kod:integrationselect add_months(sysdate,60from dual;

    ADD_MONTH
    ---------
    22-DEC-08

    Elapsed
    00:00:00.00
    17
    :35:59 kod:integrationselect sysdate+1825 from dual;

    SYSDATE+1
    ---------
    20-DEC-08

    Elapsed
    00:00:00.00
    17
    :36:07 kod:integration

Posting Permissions

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