Skip to content
Advertisement

To_CHAR(ADD_MONTHS(TRUNC(TO_DATE(’10-04-10′,’RR-MM-DD’), ‘YY’), -1), ‘Q’)

I trying to break the statement part by part to understand but it seem having some error. Appreciate if someone can explain this to me.

Thanks

select To_CHAR(ADD_MONTHS(TRUNC(TO_DATE('10-04-10','RR-MM-DD'), 'YY'), -1), 'Q')
from dual

Advertisement

Answer

TO_DATE('10-04-10','RR-MM-DD') creates a date data type with the value 10th April 2010.

TRUNC( date_value, 'YY' ) truncates the date to midnight of the first day of the year. I.e. 1st January 2010 in this case.

ADD_MONTHS( date_value, -1 ) adds -1 months to the date. I.e. 1st December 2009.

TO_CHAR( date_value, 'Q' ) outputs the quarter of the year. I.e. 4

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement