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

How to stop keep formatting using prepare / formula recipe

Solved!
abalo006
Level 3
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

0 Kudos
1 Solution

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

View solution in original post

0 Kudos
6 Replies
Turribeach

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. 

0 Kudos
abalo006
Level 3
Author

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

0 Kudos

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?

0 Kudos

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

Thanks!

0 Kudos
apichery
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

 

Labels

?
Labels (4)
A banner prompting to get Dataiku