Survey banner
The Dataiku Community is moving to a new home! We are temporary in read only mode:

# How to ad leading 0s

Level 3
###### How to ad leading 0s

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

4 Replies

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.

Level 3
Author

That formula didnt work for me

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))``````

Also this formula can add leading zeros as required:

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

Labels (3)