0

In input I have a string datetime (yyyy-mm-dd HH:MI:SS), how can I convert it to HH:MI:SS dd/mm/yyyy in output?

2
  • output also must be in string Commented Jun 5, 2020 at 10:56
  • Please clarify, as this is often a point of confusion. What is the actual data type of your "string datetime"? is it really a 'string" (varchar or varchar2) or is it of datatype DATE? If it is DATE, then you would use @Gordon Linoff answer. If it is truely a string, then you would simply use SUBSTR. Commented Jun 5, 2020 at 11:39

2 Answers 2

1

You need to convert your string --> date --> string to achieve it as follows:

 -- consider, your string is - '2020-06-05 17:48:00'

SQL> SELECT TO_CHAR(
  2  TO_DATE('2020-06-05 17:48:00',
  3  'yyyy-mm-dd HH24:MI:SS'),
  4  'HH24:MI:SS dd/mm/yyyy'
  5  ) AS RES
  6    FROM DUAL;

RES
-------------------
17:48:00 05/06/2020

SQL>
Sign up to request clarification or add additional context in comments.

2 Comments

if the input truly is a string, then there is no need to convert it to a date, just to extract the "time" part of the string. All it would need would be "substr('2020-06-05 17:48:00',12)"
But requirement is to format the date in different order.
0

You use to_char():

 select to_char(col, 'HH24:MI:SS DD/MM/YYYY')

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.