Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to display date in a different format in oracle

Tags:

date

oracle

I have a table with a date field. By default, select max(date) from table; returns the date in 'dd-mmm-yy' format. How do I select the date in 'MM/DD/YYYY' format, without changing the table 's structure or the field's format.

Thanks, Supraja

like image 668
trinity Avatar asked Nov 17 '10 08:11

trinity


People also ask

How do I display a date in YYYY-MM-DD format in Oracle?

Use TO_CHAR to display it in any format you like. For example: SELECT TO_CHAR ( TO_DATE (date_value, 'yyyy-mm-dd') , 'mm/dd/yyyy' ) FROM table_x; Things are much easier if you store dates in DATE columns.

In which format does Oracle display a date value?

Oracle stores dates in an internal numeric format representing the century, year, month, day, hours, minutes, seconds. The default date format is DD-MON-YY.


2 Answers

select to_char(max(date), 'MM/DD/YYYY') from table;
like image 194
Andrei Coșcodan Avatar answered Oct 16 '22 22:10

Andrei Coșcodan


Try the following:

select to_char(sysdate,'mm/dd/yyyy') as maxdate from dual;

Some information on the oracle-specific function to_char():

  • http://www.techonthenet.com/oracle/functions/to_char.php
like image 27
Jens Hoffmann Avatar answered Oct 16 '22 22:10

Jens Hoffmann