Monday, July 9, 2007

Oralce -- Add date

++++++++++++++++++++++++++++++++++++++++++++++++
Adding two months to current date
SQL> -- Adding two months to SYSDATE.
SQL> SELECT ADD_MONTHS(SYSDATE,2) from DUAL;

ADD_MONTH
---------
31-OCT-06

++++++++++++++++++++++++++++++++++++++++++++++++
Subtract Month from a given date
SQL> SELECT TO_CHAR(SYSDATE, 'ddMONyyyy') Today,
2 TO_CHAR(ADD_MONTHS(SYSDATE, 3), 'ddMONyyyy') "+ 3 mon",
3 TO_CHAR(ADD_MONTHS(SYSDATE, -23), 'ddMONyyyy') "- 23 mon"
4 FROM dual;

TODAY + 3 mon - 23 mon
--------- --------- ---------
30AUG2006 30NOV2006 30SEP2004

++++++++++++++++++++++++++++++++++++++++++++++++

No comments: