How to stop keep formatting using prepare / formula recipe
I have string value called hours, formatted as "00" and a value called minutes formatted as "07".
Im trying to use the concat function to create an HH:mm value = 00:07 but for some reason when using concat, it gets rid of trailing 0s and results in 0:7. is there a way around this?
if not is there any other way I can create my HH:mm value using my hours and minutes values?
Operating system used: windows
Best Answer
-
Turribeach Dataiku DSS Core Designer, Neuron, Dataiku DSS Adv Designer, Registered, Neuron 2023 Posts: 2,088 Neuron
This formula can add leading zeros as required:
concat(("00" + Hours).substring(-2), ":", ("00" + Minutes).substring(-2))
Answers
-
Turribeach Dataiku DSS Core Designer, Neuron, Dataiku DSS Adv Designer, Registered, Neuron 2023 Posts: 2,088 Neuron
Concat does not remove any leading (or trailing) zeros, it simply joins strings:
You have a different problem. Post your whole formula.
-
It looks like you're typing in "00" and "07" in quotes in your concat function, it doesn't seem to work the same way when the 00 is a field that you already have. Doing it in quotes works but, in my case, I'm referencing my "minutes" and "hours" fields
-
Turribeach Dataiku DSS Core Designer, Neuron, Dataiku DSS Adv Designer, Registered, Neuron 2023 Posts: 2,088 Neuron
What data type are Hours And Minutes and where are they coming from? Have you extract them from a date/time field? If so how?
-
Thanks!
-
Alternative (and somewhat simpler) method using the format function (https://doc.dataiku.com/dss/latest/formula/index.html#string-functions)
format("%02d:%02d", Hours, Minutes)