I have a very messy date field that is fed from several systems, each with their own date format.
I have:
DD-MM-YY hh:mm:ss.ssss
DD-MON-YY hh:mm:ss
DD-MM-YYYY hh:mm:ss.ssss
All of this is stored in a varchar2 field. Now I have to do searches between date ranges and this is causing me problems. How can I approach this?
Here are some code snippets I have tried:
A standard substr works well, but I can't account for different date formats:
select substr(created_on, 1,9) as date2 from rtl.HK_Alerts
Ideally if I can get this to work:
select to_date(created_on, 'dd-mon-yy') as date_convert from rtl.HK_Alerts
Then I can do this:
select * from my_table
where to_date(created_on, 'dd-mon-yy') > '01-Jan-1970'
and to_date(***strong text***created_on, 'dd-mon-yy') < '31-Jan-1970'
Also, how do I account for the different date formats from different systems? Unfortunately there is no system identifier I can work with.
here is a picture of some of the dates:
07-JAN-19 01.53.47.702000000
07-JAN-19 01.53.47.992000000
07-JAN-19 01.53.48.186000000
07-JAN-19 01.53.48.360000000
07-JAN-19 01.53.48.548000000
07-JAN-19 01.53.48.709000000
07-JAN-19 01.53.48.900000000
20-JAN-19 22.49.30.801000000
20-JAN-19 22.49.30.014000000
20-JAN-19 22.49.33.968000000