Reputation: 423
I'm trying with following query, it is giving me the correct date format but dates are not sorted correctly.
select to_char(date_of_service, 'mm/dd/yyyy') as service_date
from cases
order by service_date
Result I'm getting something like this (sample).
"01/01/2005"
"01/01/2010"
"01/02/2005"
"01/02/2010"
After date format I think it is getting converted into string and due to that sorting is not working. Any alternate solution available for this?
Upvotes: 0
Views: 138
Reputation:
You are sorting by the string value, not the real date value. So you need to change your ORDER BY
clause:
select to_char(date_of_service, 'mm/dd/yyyy') as service_date
from cases
order by date_of_service;
Upvotes: 1