How to stop keep formatting using prepare / formula recipe

abalo006
abalo006 Registered Posts: 29

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
    Turribeach Dataiku DSS Core Designer, Neuron, Dataiku DSS Adv Designer, Registered, Neuron 2023, Circle Member Posts: 2,722 Neuron
    edited July 2024 Answer ✓

    This formula can add leading zeros as required:

    concat(("00" + Hours).substring(-2), ":", ("00" + Minutes).substring(-2))

    Screenshot 2024-05-31 at 19.22.06.png

Answers

  • Turribeach
    Turribeach Dataiku DSS Core Designer, Neuron, Dataiku DSS Adv Designer, Registered, Neuron 2023, Circle Member Posts: 2,722 Neuron

    Concat does not remove any leading (or trailing) zeros, it simply joins strings:

    Screenshot 2024-05-31 at 09.45.21.png

    You have a different problem. Post your whole formula.

  • abalo006
    abalo006 Registered Posts: 29

    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
    Turribeach Dataiku DSS Core Designer, Neuron, Dataiku DSS Adv Designer, Registered, Neuron 2023, Circle Member Posts: 2,722 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?

  • abalo006
    abalo006 Registered Posts: 29

    Thanks!

  • apichery
    apichery Dataiker, Alpha Tester, Registered, Product Ideas Manager, Moderator Posts: 66 Dataiker

    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)

    SCR-20240604-bsda.png

Setup Info
    Tags
      Help me…