Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

TO_DATE 1

Status
Not open for further replies.

tmcneil

Technical User
Nov 17, 2000
294
0
0
US
All,

I'm sending in a date/time value as a VARCHAR2 to a stored procedure.
Code:
InDeparture: 11/29/2007 08:11:00 AM

I need to store this value into a Date field in an Oracle table. I use this line of code to convert the string date/time using TO_DATE.
Code:
departure := TO_DATE(InDeparture, 'MM/DD/YYYY HH12:MI:SS AM');

Well, the end result in the table is this.
Code:
29-Nov-2007 12:00:00 AM

I'm not sure what I need to do to get the date/time value to be like this.
Code:
29-Nov-2007 8:11:00 AM

Any suggestions?

Thanks,
Todd
 
It works fine for me:

Code:
select to_char(to_date('11/29/2007 08:11:00 AM', 'MM/DD/YYYY HH12:MI:SS AM'), 'MM/DD/YYYY HH12:MI:SS AM') from dual

11/29/2007 08:11:00 AM

It must be something else in your process which is messing up the time.
 
Dagon,

I used this:
Code:
departure := TO_CHAR(TO_DATE(InDeparture, 'MM/DD/YYYY HH12:MI:SS AM'), 'MM/DD/YYYY HH12:MI:SS AM');

It is still wiping out the time component when the data is stored in oracle.
Code:
29-Nov-2007 12:00:00 AM

Maybe it is something else, but I don't know what it is.

Todd
 
It is declared as a VARCHAR2. That could be the problem. I just changed it to a DATE and recompiled the stored procedure. I'll try that.
 
Same result.... :-(

There has got to be another way.
 
All I can say is it works fine for me:

Code:
create or replace procedure testdate(InDeparture varchar2) is 
   departure date;
begin
   departure := TO_DATE(InDeparture, 'MM/DD/YYYY HH12:MI:SS AM');
   dbms_output.put_line(to_char(departure, 'MM/DD/YYYY HH12:MI:SS AM'));
end;

set serveroutput on
begin
  testdate('11/29/2007 08:11:00 AM');
end;

11/29/2007 08:11:00 AM

 
Got it. I have two stored procedures that are identical, so I was updating the wrong one. it works! I just need to pay more attention to what I'm doing when I get frustrated.

Thanks,
Todd
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top