Hi how to transform these values into these one. (Expected_Code)
Code | Expected_Code |
202011 | 2020-11 |
202101 | 2021-01 |
201903 | 2019-03 |
Can you help me with this one pls? Thank you
hey @dunkindonut7777
(nice name btw)
Please find attached a solution that uses the formula tool:
Cheers,
TheOC
Hi @dunkindonut7777 ,
You can use this expression in the Formula tool.
Left(ToString([Code]), 4)+"-"+Right(ToString([Code]), 2)
Hi @dunkindonut7777 ,
In a formula tool, you can try the following expression
LEFT([Code],4)+"-"+Right([Code],2)
That will work only if the Code column is a String, V_String etc. If it isn't already you can stick a select tool before the formula tool and change the data type or use the ToString function
LEFT(ToString([Code]),4)+"-"+Right(ToString([Code]),2)
@dunkindonut7777 Another option is using formula -
Left(PadLeft([Code],6,"0"),4) + "-" + Right(PadLeft([Code],6,"0"),2)
And there's always regex to consider
REGEX_Replace(tostring([Code]), "(\d{4})(\d{2})", "$1-$2")
Dan
I found this discussion helpful as I was trying to turn an 8-digit string of numbers into something that looked like a date (YYYYMMDD to YYYY-MM-DD). The Regex comment was the one that helped me the most. I just modified the formula to be used with 8 digits instead of 6. I also needed to convert it to an EU formatted date like dd.mm.yyyy. It can be done in a single step as shown in output columns named "New EU formatted.....", but I left the New Start and New Finish in there in case it helped anyone see the transition.