0

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?

1
  • 1
    use order by date_of_service Commented Jan 10, 2023 at 6:30

1 Answer 1

1

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;
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.