date format from string [message #638714] |
Fri, 19 June 2015 02:19 |
mape
Messages: 298 Registered: July 2006 Location: Slovakia
|
Senior Member |
|
|
Hello
I would like to convert value of string to default oracle date format.
String values looks like:
select '[2015-06-18 14:00:31,204]' string_value from dual
I would like to get date format: 18.06.2015 14:00:31
Does anybody let me know how to do that?
Thanks
Martin
[Updated on: Fri, 19 June 2015 02:21] Report message to a moderator
|
|
|
|
|
|
Re: date format from string [message #638724 is a reply to message #638714] |
Fri, 19 June 2015 03:30 |
Lalit Kumar B
Messages: 3174 Registered: May 2013 Location: World Wide on the Web
|
Senior Member |
|
|
mape wrote on Fri, 19 June 2015 12:49
I would like to convert value of string to default oracle date format.
There is no default format for date. The format model is for display purpose. Oracle doesn't store in the format you see. Date is stored in 7 bytes in an internal Oracle's proprietary format.
Assuming that the string is stored in a fixed format:
SQL> WITH DATA AS(
2 SELECT '[2015-06-18 14:00:31,204]' string_value FROM dual
3 )
4 SELECT to_char(
5 to_date(
6 SUBSTR(string_value, 2, 19),
7 'YYYY-MM-DD HH24:MI:SS'
8 ),
9 'DD.MM.YYYY HH24:MI:SS'
10 ) my_format
11 FROM DATA;
MY_FORMAT
-------------------
18.06.2015 14:00:31
SQL>
TO_CHAR is used to display the date value in your desired format. For date arithmetic, use TO_DATE.
[Updated on: Fri, 19 June 2015 03:32] Report message to a moderator
|
|
|
|
Re: date format from string [message #638726 is a reply to message #638721] |
Fri, 19 June 2015 03:35 |
Lalit Kumar B
Messages: 3174 Registered: May 2013 Location: World Wide on the Web
|
Senior Member |
|
|
mape wrote on Fri, 19 June 2015 13:53
This string is stored in the table as varchar. I need to make it like datatype DATE.
I think you need to fix your design. Store date as date datatype, and the delimited value in different column as number. Storing the two different values in a single column is not a good idea. Specially when you are dealing with datetime values you need to be more careful.
|
|
|
Re: date format from string [message #638727 is a reply to message #638724] |
Fri, 19 June 2015 03:36 |
pablolee
Messages: 2882 Registered: May 2007 Location: Scotland
|
Senior Member |
|
|
Quote:There is no default format for date. Not exactly true Lalit. I know what you're meaning to say, but that sentence is misleading. Granted the rest of your post seems to clarify this, but that first statement is the 'anchor' that some may get hooked on.
|
|
|
|
|
Re: date format from string [message #638808 is a reply to message #638730] |
Mon, 22 June 2015 03:21 |
mape
Messages: 298 Registered: July 2006 Location: Slovakia
|
Senior Member |
|
|
I would like to get fixed format (see below )into date format
to_char(
to_date(
SUBSTR(col1, 2, 19),
'YYYY-MM-DD HH24:MI:SS'
),
'DD.MM.YYYY HH24:MI:SS'
)
How should I do that?
Thanks
|
|
|
|
|
|
|
|
|