Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17


convert date to timestamp Oracle

Posted on 2014-12-12
Medium Priority
Last Modified: 2014-12-15
Hi experts, I need to convert a date column:
'11-DEC-14 PM'

Open in new window

'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!
Question by:carlino70
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
  • 2
  • +2
LVL 59

Expert Comment

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

what data you have now?
LVL 35

Expert Comment

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 ->

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.
LVL 59

Expert Comment

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


select TO_TIMESTAMP('11-DEC-14 PM', 'DD-MON-YY HH.MI.SS.FF6 PM') from dual
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.


Author Comment

ID: 40500585
SQL> SELECT TO_TIMESTAMP(TO_CHAR(sysdate,'dd-Mon-yy HH24:MI:SS'),'dd-mon-yyyy HH24:MI:SS') salida FROM dual;
15-DEC-14 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;

Open in new window

That is the solution.
LVL 77

Assisted Solution

by:slightwv (䄆 Netminder)
slightwv (䄆 Netminder) earned 1000 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;
LVL 35

Accepted Solution

johnsone earned 1000 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') from dual;

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

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 ;-)

Author Closing Comment

ID: 40501227

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Working with Network Access Control Lists in Oracle 11g (part 2) Part 1: Previously, I introduced the basics of network ACL's including how to create, delete and modify entries to allow and deny access.  For many…
How to Unravel a Tricky Query Introduction If you browse through the Oracle zones or any of the other database-related zones you'll come across some complicated solutions and sometimes you'll just have to wonder how anyone came up with them.  …
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
This video shows how to Export data from an Oracle database using the Datapump Export Utility.  The corresponding Datapump Import utility is also discussed and demonstrated.

670 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