Say I have a field numCommande with a string "1610131223ZVV40" where 161013 is a date in form yymmdd.
Is there any way in SQL to extract that 13/10/2016 date from the string field ?
Thanks!
If the 'date' is always the first six characters, you can extract those with a plain substr() call:
substr(numCommande, 1, 6)
which gives you '161013'; and then convert that string to a date with a suitable format model:
select to_date(substr(numCommande, 1, 6), 'RRMMDD') from your_table;
Quick demo with static value instead:
select to_date(substr('1610131223ZVV40', 1, 6), 'RRMMDD') from dual;
TO_DATE(SU
----------
2016-10-13
RR over YYSELECT TO_CHAR(TO_DATE(SUBSTR(Column_Name,1,6), 'YYMMDD'),'DD/MM/YYYY') FROM TableName
Live Demo
substr()andto_date()would be enough. What have you tried so far?