3

I have a date format in the form dd.mm.yyyy I want to convert it mm/dd/yyyy. Is it possible?

All the articles on the internet I read had dd/mm/yyyy to mm/dd/yyyy was possible and it worked when I tried.

But when I put dd.mm.yyyy it does not work? How can I fix it?

Please help me

2
  • Are you working with a "date" column or a "varchar2" with formatted text? An actual date column can be formatted on select to display as whatever format you want with to_char. Use to_date to format text as a date data type if you are inserting or updating. Commented Oct 31, 2020 at 13:57
  • What is doing the displaying? The storage format and the display format are two different things. Commented Nov 1, 2020 at 11:19

2 Answers 2

2

Oracle stores dates using an internal format. If you have a string that represents a date, you should probably fix your data model, so the column has the correct data type.

In the meantime, you can convert it to a date using:

select to_date(col, 'dd.mm.yyyy')

You can convert this back to a string:

select to_char(to_date(col, 'dd.mm.yyyy'), 'mm/dd/yyyy')
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks alot. If I want to include the time format like the following how is it possible? select to_char(to_date('16.12.2020 10:10:20 PM', 'dd.mm.yyyy'), 'mm/dd/yyyy') from dual. This gave an error
You would include the time format elements in to_date()/to_char(). These are well documented.
1

I have a date format in the form dd.mm.yyyy

Assuming that you mean a DATE data type then, no, you don't have it in the format dd.mm.yyyy. A DATE data type value is stored within the database as a binary value in 7-bytes (representing century, year-of-century, month, day, hour, minute and second) and this has no format.

I want to convert it mm/dd/yyyy. Is it possible?

No, because DATE data types do not have a format.

However, what you probably meant to ask is:

I want to convert display as it mm/dd/yyyy. Is it possible?

Yes, use TO_CHAR with the appropriate format models:

SELECT TO_CHAR( date_value, 'mm/dd/yyyy' )
FROM   table_name

If you mean that you have a CHAR or VARCHAR2 data type storing date values in the format dd.mm.yyyy then use TO_DATE to convert it to a DATE data type and then TO_CHAR to display it to the format you want.

SELECT TO_CHAR( TO_DATE( string_value, 'dd.mm.yyyy' ), 'mm/dd/yyyy' )
FROM   table_name

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.