Home > Enterprise >  Trouble with convert integer to date time in Oracle
Trouble with convert integer to date time in Oracle

Time:10-20

i have in table one column in integer. This integer looks like:

2204010044 - it is YYMMDDHH24MI.

I want this column in sql query convert to date. But when i try, i get error: ORA-01840. I testing this: TO_DATE("mycolumn",'yymmddhh24mi') I've tried multiple options, but always to no avail.

NLS_DATE_FORMAT is for database: DD.MM.YY (i dont know,if its relevant)

CodePudding user response:

Maybe with something like this:

select to_timestamp(cast(2204010044 as varchar(10)),'YYMMDDHH24MI') 
from dual

If you want to keep the time, you must cast to timestamp, not date.

If you want just the date, use:

select to_date(2204010044,'YYMMDDHH24MI') 
from dual

You can test on this db<>fiddle

CodePudding user response:

Try the following SQL query:

select TO_DATE(2204010044,'yymmdd hh24:MI:ss')
  FROM dual 

dbfiddle

  • Related