Question

I am trying to extract the below query:

select
'<tr><td>'||column1||'</td>',
'<td>'||column2||'</td>',
'<td>'||column3||'</td></tr>'
from table

In the above, column3 is a date field. When the output is printed, it is ignoring the time part. For example:

If columns 3 output is : 5/25/2011 3:03:17 AM
The above query returns : <tr><td>column1</td><td>column2</td><td>**25-JUN-11**</td></tr>

I have tried to_date(column3,'yyyy/mm/dd HH24:MI:SS') and also, the normal query prints the time

select
column1,
column2,
column3,
from table

columns 3 prints time. Any help is appreciated.

EDIT: I am using Oracle 10g. I have also tried it in Oracle 9i

Was it helpful?

Solution

Don't rely on implicit conversions, use TO_CHAR to display a date to your liking:

select '<tr><td>'||column1||'</td>', 
       '<td>'||column2||'</td>', 
       '<td>'||to_char(column3, 'dd/mm/yyyy hh24:mi:ss')||'</td></tr>' 
  from table 

OTHER TIPS

TO_DATE does exactly what it's supposed to do, format mask supplies it with the format it's primary input is in so it can transform it into a date. The format mask is not used to define output but input. What you need to use instead is TO_CHAR

TO_CHAR(column3,'yyyy/mm/dd HH24:MI:SS') 
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top