Month number with 2 digits (April = 04)

Hi,
I’m using Concatenate() on a field in my table.
Concatenate(Date.Month(), Client, Value)
I need that the month has 2 digits, not only one.
So April should be 04 and not 4.
How can I specify this?
Thanks.

@Alessandro_Scaltritti ,
you might consider Coda | Formula library (LeftPad)
it will do the trick
enjoy, Christiaan

1 Like

Dear @Alessandro_Scaltritti,

Personally I prefer the format formula, like in the below sample:

image

I also tend to prefer Format() formula, as it’s usually a bit more flexible.

Also, it has a pre-built in pattern, so you can write
Format("{1:00}, [Date].Month()") You can set the number of digits after “:”
and you’ll have the leading zero only when necessary.

(@Jean_Pierre_Traets, in your case it would put a leading zero also in two digits months).

I hope it helps!

3 Likes

Dear @Federico_Stefanato,

Thanks a lot for the great advise, much appreciated feedback. :trophy:

2 Likes

OK,
at the end I have this working formula:

Concatenate(Date.year().Format("{1:00}"), Date.month().Format("{1:00}"), Date.Day().Format("{1:00}") , Client, Value)

I think it could be better but it works and that’s enough.
Thank to everyone!

1 Like

Hi @Alessandro_Scaltritti ,

Since Format() takes a list of ordered parameters, you might find this even more convenient:

Format("{1}{2:00}{3:00}{4}{5}", 
  [Date].Year().Right(2), 
  [Date].Month(), 
  [Date].Day(), 
  [Client], 
  [Value])

So you can get rid of Concatenate() altogether.

In case of year - being it a 4 digit - the pattern would not work: as it “fills” with leading zeroes until the length. i.e. it doesn’t cut the value.

Feel free to ask if it’s not clear.
Cheers!

5 Likes

Good! Really clever. Thanks a lot!