How to ad leading 0s

abalo006
abalo006 Registered Posts: 29

I have a column called minutes and that can range from 0 - 60, what I'm trying to do is add a leading 0 to the single digit values,

ex 9 = 09, so that no matter what my value is always 2 digits long, is that possible? and if so, how would I accomplish that?


Operating system used: windows

Answers

  • Turribeach
    Turribeach Dataiku DSS Core Designer, Neuron, Dataiku DSS Adv Designer, Registered, Neuron 2023 Posts: 2,088 Neuron

    You have not responded to my answer in your other thread which seems to be related to this. Perhaps you are trying to calculate the difference between two dates and display the result in hh:mm:ss format? This 6 year old post shows how to do that.

  • abalo006
    abalo006 Registered Posts: 29

    That formula didnt work for me

  • Turribeach
    Turribeach Dataiku DSS Core Designer, Neuron, Dataiku DSS Adv Designer, Registered, Neuron 2023 Posts: 2,088 Neuron
    edited July 17

    You need to make sure you don't break the formula lines in the wrong place. Try with this text which uses a code block and should add extra line breaks:

    "00"[0,2-(floor(diff(last_working_day, Date_parsed, "seconds")/3600)).length()] + (floor(diff(last_working_day, Date_parsed, "seconds")/3600)) + ':'
    + "00"[0,2- (floor(mod(diff(last_working_day, Date_parsed, "seconds"), 3600)/60)).length()] + (floor(mod(diff(last_working_day, Date_parsed, "seconds"), 3600)/60))
    + ':'
    + "00"[0,2- (mod(mod(diff(last_working_day, Date_parsed, "seconds"), 3600),60)).length()] + (mod(mod(diff(last_working_day, Date_parsed, "seconds"), 3600),60))

    Screenshot 2024-05-31 at 19.05.02.png

  • Turribeach
    Turribeach Dataiku DSS Core Designer, Neuron, Dataiku DSS Adv Designer, Registered, Neuron 2023 Posts: 2,088 Neuron
    edited July 17

    Also 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

Setup Info
    Tags
      Help me…