danh chau
danh chau

Reputation: 3

How to convert a string to datetime

I have a string like 'Jul 18, 2013 11:06:23 AM' I want to display it like '07/18/2013 11:06:23 AM' I try to to use To_date function (oracle function) to convert it, however I got error. Please help me!

Upvotes: 0

Views: 128

Answers (2)

CHHIBI AMOR
CHHIBI AMOR

Reputation: 1265

Try this, it works very well:

select to_char(to_date('Jul 18, 2013 11:06:23','MON DD, YYYY HH:MI:SS',
  'NLS_DATE_LANGUAGE = American'),'MM/DD/YYYY HH:MI:SS AM') from dual

You can adapt to your problem.

Upvotes: 4

Exhausted
Exhausted

Reputation: 1885

You want to use the following conversion function

to_date(mystring, 'Mon DD, YYYY HH:MI:SS AM')

where your string is like in the above format, you have to use the format string based on your input string.

If you want to display the date in above format you have to use TO_CHAR function like below

select to_char(mydate, 'DD/MM/YYYY HH:MI:SS AM') from yourtable

check here for more information http://docs.oracle.com/cd/B19306_01/server.102/b14200/functions180.htm

Upvotes: 0

Related Questions