Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert number to date sql oracle

I'm trying to convert a number (yyyymmdd) to date (mm/dd/yyyy)

For example

20150302 ====> 03/02/2015
like image 699
Dev_dev Avatar asked Jul 14 '15 11:07

Dev_dev


2 Answers

You can try this:

select to_date(20150302,'yyyymmdd') from dual;

or

select to_char(to_date(20150302,'yyyymmdd'),'mm/dd/yyyy') from dual;
like image 132
Stefan Yordanov Avatar answered Sep 21 '22 08:09

Stefan Yordanov


The above answer is still incorrect. It returns a character string when a date is needed. The correct way is:

select to_date(to_char(20210416), 'YYYYMMDD') num_to_char_to_date from dual;
like image 32
yanway Avatar answered Sep 22 '22 08:09

yanway