I have a requirement where a filed value is "CAH132242F0A" from this i have to come up with a date.
so here "13" is the year and so yyyy = "2013" and "224" th day. so i have to extract this and make it a date format "yyyy-mm-dd".
Can someone help me how to do it?
5
Answers
You could use some string manipulation olympics here:
Demo
Here we use
TIMESTAMPADD
and brute force substring operations to add the correct number of days to January 1 in the year specified.According to the databricks docs on date/time formats this should work:
We extract the five digits for yyddd and apply the format ‘yD’ where y stands for a two- or four-digit year and D for a three-digit day number. The docs say that the base year is always 2000, which is just what you want.
Use
date_add
twice: once for the year, and again for the day:See live demo.
The date is 2013-08-12 (and not 13 !)
Query:
fiddle