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
SELECT TO_CHAR(TO_DATE(SUBSTR(Column_Name,1,6), 'YYMMDD'),'DD/MM/YYYY') FROM TableName
Live Demo
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.