Friday, July 13, 2018

Finding first day and last day of the year in Oracle

I am thinking these are the easiest way to find out the first day and last day of a year in oracle.  If you have one please write in a comment. I will update it here. thanks.

First Day of Previous Year

SELECT ADD_MONTHS (TRUNC (SYSDATE,’YEAR’), -12) FROM DUAL;

Last Day of Previous Year

SELECT ADD_MONTHS (TRUNC (SYSDATE, ‘YEAR’), -1 ) +30 FROM DUAL;

First Day of Current Year

SELECT TRUNC (SYSDATE , ‘YEAR’) FROM DUAL;

Last Day of Current Year

SELECT ADD_MONTHS(TRUNC (SYSDATE ,’YEAR’),12)-1 FROM DUAL;