Friday, 5 April 2013

To find out previous, current and next years first date and last date

/* Formatted on 4/5/2013 3:29:30 PM (QP5 v5.114.809.3010) */
SELECT   TRUNC (
            LAST_DAY (
               ADD_MONTHS (SYSDATE, -TO_NUMBER (TO_CHAR (SYSDATE, 'mm')))
            ),
            'YEAR'
         )
            privious_year_first_date,
         TRUNC(LAST_DAY (
                  ADD_MONTHS (SYSDATE, -TO_NUMBER (TO_CHAR (SYSDATE, 'mm')))
               ))
            privious_year_last_date,
         TRUNC (
            LAST_DAY (
               ADD_MONTHS (SYSDATE, 12 - TO_NUMBER (TO_CHAR (SYSDATE, 'mm')))
            ),
            'YEAR'
         )
            current_year_first_date,
         TRUNC(LAST_DAY(ADD_MONTHS (SYSDATE,
                                    12 - TO_NUMBER (TO_CHAR (SYSDATE, 'mm')))))
            current_year_last_date,
         TRUNC (
            LAST_DAY (
               ADD_MONTHS (SYSDATE, 24 - TO_NUMBER (TO_CHAR (SYSDATE, 'mm')))
            ),
            'YEAR'
         )
            next_year_first_date,
         TRUNC(LAST_DAY(ADD_MONTHS (SYSDATE,
                                    24 - TO_NUMBER (TO_CHAR (SYSDATE, 'mm')))))
            next_year_last_date
  FROM   DUAL

No comments:

Post a Comment