Solved

Oracle varchar to datetime

Posted on 2006-06-22
10
3,516 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 142

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

Title # Comments Views Activity
Consolidating oracle query results to a single line 8 60
Oracle Listener Not Starting 11 44
use lov values 2 51
upgrading Oracle 10g/ 11g / 11g R2 to Oracle 12c 25 55
This article started out as an Experts-Exchange question, which then grew into a quick tip to go along with an IOUG presentation for the Collaborate confernce and then later grew again into a full blown article with expanded functionality and legacy…
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.
This video shows setup options and the basic steps and syntax for duplicating (cloning) a database from one instance to another. Examples are given for duplicating to the same machine and to different machines
This video shows syntax for various backup options while discussing how the different basic backup types work.  It explains how to take full backups, incremental level 0 backups, incremental level 1 backups in both differential and cumulative mode a…

832 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