7/14/17

Sorting dates using only month and year

In PL/SQL in order to show only the month and year of a date, you need to convert the date to char, once you do that the order by get messed up because it won't recognize the field as a date anymore so SEP-2006 will come before OCT-2016 if you are using order by desc. To solve this issue you can do the following select DISTINCT to_char(x_date, 'MON-YYYY') DISPLAY, to_char(x_date, 'YYYY-MM') HIDDEN order by to_char(x_date, 'YYYY-MM') DESC;

No comments: