Solved

Oracle varchar to datetime

Posted on 2006-06-22
10
3,519 Views
Last Modified: 2008-01-09
I have a stored procedure that takes varchar parameter. I convert this to date with the following function, how can I add default time to it.

open_date is a varchar2 , how can I add time to it .

Open_Date                    = to_date(p_BM_Open_Date, 'mm/dd/yyyy')

eg: instead of 6/21/2006 it should update the table with 6/21/2006 4:05:10 PM





0
Comment
Question by:tech_question
  • 4
  • 2
  • 2
  • +2
10 Comments
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 16963640
>how can I add default time to it.

what time do you want to add to the date?

Open_Date                 = to_date(p_BM_Open_Date || ' 16:05:10', , 'mm/dd/yyyy hh24:mi:ss')
0
 

Author Comment

by:tech_question
ID: 16963661
default time from sysdate function.
0
 

Author Comment

by:tech_question
ID: 16963675
rather the current time of the system when the transaction is taking place.
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 14

Accepted Solution

by:
sathyagiri earned 400 total points
ID: 16963676
If your input parameter has a time componenet use

open_date =  to_date(p_BM_Open_Date , 'mm/dd/yyyy hh24:mi:ss')

if it doesn't try this
open_date = to_date(p_BM_Open_Date||to_char(sysdate,'hh24:mi:ss') ,
 'mm/dd/yyyyh24:mi:ss')
0
 

Author Comment

by:tech_question
ID: 16963752
I am getting ora-01821 error date format not recognised.
0
 
LVL 19

Expert Comment

by:actonwang
ID: 16963758
how does your p_BM_Open_Date  look like?

as angeIII said, you'd use to_date function but it depends on how your pass the date string in?
0
 
LVL 19

Expert Comment

by:actonwang
ID: 16963763
refer to this when you construct the date format:

http://www.ss64.com/orasyntax/fmt.html
0
 
LVL 25

Assisted Solution

by:jrb1
jrb1 earned 100 total points
ID: 16963771
how about:

open_date = to_date(p_BM_Open_Date||' ' ||to_char(sysdate,'hh24:mi:ss') ,
 'mm/dd/yyyy hh24:mi:ss')
0
 

Author Comment

by:tech_question
ID: 16963812
actually I messed with something , I removed the h from hh24. I did add the space though after the date.

Thanks JRB1 for pointing it out.
0
 
LVL 14

Expert Comment

by:sathyagiri
ID: 16963932
I think I amde a typo..
open_date = to_date(p_BM_Open_Date||to_char(sysdate,'hh24:mi:ss') ,
 'mm/dd/yyyyh24:mi:ss')

should have been
open_date = to_date(p_BM_Open_Date||to_char(sysdate,'hh24:mi:ss') ,
 'mm/dd/yyyyhh24:mi:ss')

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.

Question has a verified solution.

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

Suggested Solutions

Working with Network Access Control Lists in Oracle 11g (part 1) Part 2: http://www.e-e.com/A_9074.html So, you upgraded to a shiny new 11g database and all of a sudden every program that used UTL_MAIL, UTL_SMTP, UTL_TCP, UTL_HTTP or any oth…
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
Via a live example show how to connect to RMAN, make basic configuration settings changes and then take a backup of a demo database
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.

829 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