In my application date formats are configurable and it is stored in one of the following formats in the table:
d.m.Y --> represents dd.mm.rrrr
d.m.y --> represents dd.mm.rr
Y.m.d --> represents rrrr.mm.dd
y.m.d --> represents rr.mm.dd
I need to use it in my queries and procedures to show the dates in the format specified by user which can be done by TO_CHAR(any_date, date_format)
but, I will need to convert these values to the format that Oracle can recognize.
Currently, I am using REPLACE
to achieve this as follows:
TO_CHAR(<my_date_column>, REPLACE(
REPLACE(
REPLACE(
REPLACE('<date_format>',
'd', 'dd'),
'm', 'mm'),
'Y', 'rrrr'),
'y', 'rr'))
I am curious to know if there is another way of doing the same. May be using REGEXP_REPLACE
or some other way.