convert char to date [message #616865] |
Sat, 21 June 2014 14:25 |
mape
Messages: 298 Registered: July 2006 Location: Slovakia
|
Senior Member |
|
|
Hi
I'd would like to know to get a righ date format of string for example 20140501130926 ?
I need to conver into the format dd.mm.yyyy h24:mi:ss
This varchar string 20140501130926 consist of number of data yyyymmddh24miss
I tried to use to_date(20140501130926, 'yyyymmdd h24:mi:ss') or to_char(20140501130926, 'yyyymmdd h24:mi:ss')
but unsuccessfully.
Thanks for help.
Regards
Martin
|
|
|
|
|
Re: convert char to date [message #616924 is a reply to message #616869] |
Mon, 23 June 2014 02:45 |
cookiemonster
Messages: 13920 Registered: September 2008 Location: Rainy Manchester
|
Senior Member |
|
|
Littlefoot wrote on Sat, 21 June 2014 20:36You can't use format mask that doesn't exist in input string. Where do you see colons in 20140501130926? There are none!
Oracle is very forgiving about missing separators. The problem in this case is that h24 isn't valid:
SQL> SELECT to_date(20140501130926, 'yyyymmdd h24:mi:ss') FROM dual;
SELECT to_date(20140501130926, 'yyyymmdd h24:mi:ss') FROM dual
ORA-01821: date format not recognized
SQL> --add missing h.
SQL> SELECT to_date(20140501130926, 'yyyymmdd hh24:mi:ss') FROM dual;
TO_DATE(20140501130926,'YYYYMM
------------------------------
20140501 13:09:26
SQL>
|
|
|
|
Re: convert char to date [message #616944 is a reply to message #616939] |
Mon, 23 June 2014 08:10 |
cookiemonster
Messages: 13920 Registered: September 2008 Location: Rainy Manchester
|
Senior Member |
|
|
It would have helped if the OP had supplied the error message in first place, I didn't spot the actual mistake until I ran it myself, on seeing the real error I studied the format string a lot closer.
|
|
|