How can I change the format of a date in SQL Language?

2

I am working with the HR SQL database (ORACLE), and I would like to know how to change the date format

Current format

  • 06/17/03

Future or expected format

  • June 17, 2003
asked by Manuel Ramirez 08.03.2018 в 14:46
source

2 answers

1

If you want to retrieve the results stored in BDD with this format, in the selects you use to obtain the dates you can use this formatting. Surely there is some more efficient way, but hey, I leave it here:

select to_char(col_fecha, 'DD') || ' de ' ||to_char(col_fecha, 'MONTH') || ' del año ' || to_char(col_fecha, 'YYYY') 
from tabla;

If the field is nullable you will need to enter a CASE WHEN to control those specific cases.

    
answered by 08.03.2018 / 15:36
source
0

Complex cases are not necessary, TO_CHAR can handle the format. You just need to pass the code of value NLS_DATE_LANGUAGE adequate. The accepted solution may not be the correct result (for the value of the month) if the NLS_DATE_LANGUAGE of the session is other than SPANISH

SELECT TO_CHAR(CAMPO_FECHA, 'DD "de" Month "del año" YYYY', 'NLS_DATE_LANGUAGE=SPANISH') FROM tabla;

Exit:

08 de Marzo del año 2018
    
answered by 08.03.2018 в 16:37