dbTalk Databases Forums  

format date with Oracle Dynamic SQL

comp.databases.oracle comp.databases.oracle


Discuss format date with Oracle Dynamic SQL in the comp.databases.oracle forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
deadlocklegend@gmail.com
 
Posts: n/a

Default format date with Oracle Dynamic SQL - 03-01-2005 , 11:52 AM






Hi all,

when i set a date field's type (12) to VARCHAR2 or STRING, I get the
date (mm/dd/yyyy) correct, but I can never get the time which is always
set to 00:00:00 even if i increase the buffer size? Is there anyway to
force pro*c to format correctly without using to_char because with
to_char i lose the ability to keep track of correct data type.

Thanks


Reply With Quote
  #2  
Old   
Frank van Bortel
 
Posts: n/a

Default Re: format date with Oracle Dynamic SQL - 03-01-2005 , 12:58 PM






deadlocklegend (AT) gmail (DOT) com wrote:
Quote:
Hi all,

when i set a date field's type (12) to VARCHAR2 or STRING, I get the
date (mm/dd/yyyy) correct, but I can never get the time which is always
set to 00:00:00 even if i increase the buffer size? Is there anyway to
force pro*c to format correctly without using to_char because with
to_char i lose the ability to keep track of correct data type.

Thanks

Dates are stored internally as numbers, and always
include a time fraction.

The display (or format) mask is what makes it visible
as a date - but you must specify it.
What you experience is the default date format, try
to select to_char([your_date_column],'dd-Mon-yyyy HH24:MI:SS')
from your_table.

All date format masks are documented; search tahiti.oracle.com
--
Regards,
Frank van Bortel


Reply With Quote
  #3  
Old   
deadlocklegend@gmail.com
 
Posts: n/a

Default Re: format date with Oracle Dynamic SQL - 03-01-2005 , 01:14 PM



we are dynamically retrieving data types of a dynamic query and build
an XML resultset. to_char i believe gives us a string type when we
wanted a date type for that field. Is there a way to do it?


Reply With Quote
  #4  
Old   
Frank van Bortel
 
Posts: n/a

Default Re: format date with Oracle Dynamic SQL - 03-01-2005 , 03:43 PM



deadlocklegend (AT) gmail (DOT) com wrote:
Quote:
we are dynamically retrieving data types of a dynamic query and build
an XML resultset. to_char i believe gives us a string type when we
wanted a date type for that field. Is there a way to do it?

to_date(string, format_mask)

What other documentation shall I read you?

--
Regards,
Frank van Bortel


Reply With Quote
  #5  
Old   
deadlocklegend@gmail.com
 
Posts: n/a

Default Re: format date with Oracle Dynamic SQL - 03-01-2005 , 08:46 PM



sorry about bothering you, but when i do something like

select to_date(to_char(date_column, 'yyyy-mm-dd hh24:mi:ss'),
'yyyy-mm-dd hh24:mi:ss') from table_name

in my pro*c code, i get back

2005-02-24 00:00:00

when data is 2005-02-24 11:05:07


Reply With Quote
  #6  
Old   
Jim Kennedy
 
Posts: n/a

Default Re: format date with Oracle Dynamic SQL - 03-01-2005 , 08:53 PM




<deadlocklegend (AT) gmail (DOT) com> wrote

Quote:
sorry about bothering you, but when i do something like

select to_date(to_char(date_column, 'yyyy-mm-dd hh24:mi:ss'),
'yyyy-mm-dd hh24:mi:ss') from table_name

in my pro*c code, i get back

2005-02-24 00:00:00

when data is 2005-02-24 11:05:07
get rid of the to_date. Doesn't ProC have a native date interface?
Wouldn't it make more sence to use that?
Jim
Quote:



Reply With Quote
  #7  
Old   
Mark C. Stock
 
Posts: n/a

Default Re: format date with Oracle Dynamic SQL - 03-02-2005 , 03:25 AM




<deadlocklegend (AT) gmail (DOT) com> wrote

Quote:
sorry about bothering you, but when i do something like

select to_date(to_char(date_column, 'yyyy-mm-dd hh24:mi:ss'),
'yyyy-mm-dd hh24:mi:ss') from table_name

in my pro*c code, i get back

2005-02-24 00:00:00

when data is 2005-02-24 11:05:07

the TO_DATE is using the default date format (NLS_DATE_FORMAT) to convert
back to a date column -- that is likely truncating the time element

if you want a date, don't use either to_date or to_char

if you need to convert to or from a date datatype, us to_date or to_char
(seldom are both ever used together) with the appropirate date format -- or
use ALTER SESSION to set the default date format for your session

++ mcs




Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.