Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6330087
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T17:48:09+00:00 2026-05-24T17:48:09+00:00

In my application am trying to format and sort the date, i am using

  • 0

In my application am trying to format and sort the date, i am using to_char() function to format the date to my required format, but when i sort them it is sorting it as string sorting. But i want them to be sorted as date.

I need some help to achieve both in the same query. Kindly help me on the same.

The query which i used was,

SELECT to_char( t1.your_date_column1, your_format_mask ) as alias,
  FROM your_table1 t1,your_table2
 ORDER BY t1.your_date_column1
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T17:48:12+00:00Added an answer on May 24, 2026 at 5:48 pm

    It sounds like you want something like

    SELECT to_char( your_date_column, your_format_mask )
      FROM your_table
     ORDER BY your_date_column
    

    In the SELECT list, you want to return a character string that represents the date in your preferred format. In the ORDER BY clause, you want to order by the actual date. Using the standard EMP and DEPT tables, for example

    SQL> ed
    Wrote file afiedt.buf
    
      1  select to_char( hiredate, 'DD-MM-YYYY' )
      2    from emp,
      3         dept
      4   where emp.deptno = dept.deptno
      5*  order by hiredate
    SQL> /
    
    TO_CHAR(HI
    ----------
    17-12-1980
    20-02-1981
    22-02-1981
    02-04-1981
    01-05-1981
    09-06-1981
    08-09-1981
    28-09-1981
    17-11-1981
    03-12-1981
    03-12-1981
    23-01-1982
    19-04-1987
    23-05-1987
    
    14 rows selected.
    

    If you add a DISTINCT, the problem is that Oracle doesn’t know that the function you are applying (in this case TO_CHAR) provides a one-to-one mapping from the data in the table to the data in the output. For example, two different dates (October 1, 2010 10:15:15 and October 1, 2010 23:45:50) might generate the same character output, forcing Oracle to eliminate one of the two ’01-10-2010′ strings but the two dates would sort differently. You can rectify that problem by nesting your query and converting the string back to a date after doing the DISTINCT and before doing the ORDER BY

    SQL> ed
    Wrote file afiedt.buf
    
      1  select hire_date_str
      2    from (
      3      select distinct to_char( hiredate, 'DD-MM-YYYY' ) hire_date_str
      4        from emp,
      5             dept
      6       where emp.deptno = dept.deptno
      7      )
      8*  order by to_date(hire_date_str,'DD-MM-YYYY')
    SQL> /
    
    HIRE_DATE_
    ----------
    17-12-1980
    20-02-1981
    22-02-1981
    02-04-1981
    01-05-1981
    09-06-1981
    08-09-1981
    28-09-1981
    17-11-1981
    03-12-1981
    23-01-1982
    19-04-1987
    23-05-1987
    
    13 rows selected.
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to format French Canadian currencies in my multi-lingual application. I'm using an
in my application i trying to implement the cache (ouput) but it is not
I'm trying to format an excel column that I created in a .net application.
When I'm trying to open my javafx application in jnlp format I'm getting the
I'am trying to rewrite zend framework configuration file from application.ini to application.yml format and
im trying to send a Windows message to my Delphi application, but im having
I am trying to create a simple application using SpringMVC for learning purpose. I
I'm trying to create test users for my Facebook application using the Facebook C#
I'm trying to create a chat with file transfer application using TCPSocket and here
I'm trying to format the 'date' parameter in the fullCalendar dayClick so it's passed

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.