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

How to ad leading 0s

abalo006
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

0 Kudos
4 Replies
Turribeach

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
Level 3
Author

That formula didnt work for me

0 Kudos

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

 

 

0 Kudos

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

0 Kudos

Labels

?
Labels (3)
A banner prompting to get Dataiku