Solved

convert date to timestamp Oracle

Posted on 2014-12-12
8
3,820 Views
Last Modified: 2014-12-15
Hi experts, I need to convert a date column:
'11-DEC-14 01.17.00.801271 PM'

Open in new window

on:
'11/12/2104 01:17:00.801271'

Open in new window

I Known that I must use to_timestamp, but I can´t find the solution.

Could you help me with this issue?
Thanks, is urgent!
Regards
0
Comment
Question by:carlino70
  • 2
  • 2
  • 2
  • +2
8 Comments
 
LVL 51

Expert Comment

by:HainKurt
ID: 40496871
you convert string to date?
date to string?

what data you have now?
0
 
LVL 34

Expert Comment

by:johnsone
ID: 40496877
What is the datatype of the original?  It cannot be a date because I see fractional seconds.  I assume it is a timestamp and you are looking to make a different format?

The format elements are listed here -> http://docs.oracle.com/cd/E11882_01/server.112/e41084/sql_elements004.htm#i34948

What you are showing would be TO_CHAR(col1, 'dd/mm/yyyy hh:mi:ss.ff6')

However, you may actually want TO_CHAR(col1, 'dd/mm/yyyy hh24:mi:ss.ff6')  so that you can differentiate between AM and PM.
0
 
LVL 51

Expert Comment

by:HainKurt
ID: 40496894
select TO_TIMESTAMP('11-DEC-14 01.17.00.801271 PM', 'DD-MON-YY HH.MI.SS.FF PM') from dual

or

select TO_TIMESTAMP('11-DEC-14 01.17.00.801271 PM', 'DD-MON-YY HH.MI.SS.FF6 PM') from dual
0
 

Author Comment

by:carlino70
ID: 40500585
Again:
SQL> SELECT TO_TIMESTAMP(TO_CHAR(sysdate,'dd-Mon-yy HH24:MI:SS'),'dd-mon-yyyy HH24:MI:SS') salida FROM dual;
SALIDA
---------------------------------------------------------------------------
15-DEC-14 03.54.00.000000000 PM

Open in new window

But with the adding:
SQL> SELECT substr(TO_TIMESTAMP(TO_CHAR(sysdate,'dd-Mon-yy HH24:MI:SS'),'dd-mon-yyyy HH24:MI:SS'),1,28) salida FROM dual;
SALIDA
----------------------------
15-DEC-14 03.53.32.000000000

Open in new window

That is the solution.
Thanks
0
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
LVL 76

Assisted Solution

by:slightwv (䄆 Netminder)
slightwv (䄆 Netminder) earned 250 total points
ID: 40500597
If the column is already a DATE data type, there is no need for all the to_char and to_timestamp stuff.  No need to take it to a string and then back:

select cast(sysdate as timestamp) from dual;
0
 
LVL 34

Accepted Solution

by:
johnsone earned 250 total points
ID: 40500600
Why are you taking a date, converting it to a string, converting it to a timestamp and then back to a string?

Why wouldn't you use:

select to_char(systimestamp, 'dd-MON-yy hh24.mi.ss.ff') from dual;

That should give you the exact same thing without all the conversions.
0
 
LVL 13

Expert Comment

by:Alexander Eßer [Alex140181]
ID: 40500603
I totally agree with slightwv: I don't see any purpose (that would make sense) in all that converting back and forth. Keep it as simple as possible ;-)
0
 

Author Closing Comment

by:carlino70
ID: 40501227
Thanks!
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Join & Write a Comment

Why doesn't the Oracle optimizer use my index? Querying too much data Most Oracle developers know that an index is useful when you can use it to restrict your result set to a small number of the total rows in a table. So, the obvious side…
Working with Network Access Control Lists in Oracle 11g (part 2) Part 1: http://www.e-e.com/A_8429.html Previously, I introduced the basics of network ACL's including how to create, delete and modify entries to allow and deny access.  For many…
This video shows information on the Oracle Data Dictionary, starting with the Oracle documentation, explaining the different types of Data Dictionary views available by group and permissions as well as giving examples on how to retrieve data from th…
This video shows how to Export data from an Oracle database using the Original Export Utility.  The corresponding Import utility, which works the same way is referenced, but not demonstrated.

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now