FORMAT VALUE: Pad a Number with Leading Zeros / Force an Integer To Be At Least 2 Digits Long

Dear All,

I am having a struggle in my project due to format value.

The case is that I am willing to get an Integer like 1, 2,…, 9 and format them into two digits.
(Is related to convert the just the value DateTime.Now.Month.ToString with 2 digits adding 0s in case)
I mean I would like that the outcome (.ToString) 01, 02,…, 09 and so on.

Any idea will be welcomed!
I already tried with FormatValue and doesn’t have the option…
I also tried with, MyInteger.ToString(“D”).Length, but it doesn’t work

Thanks a lot in advance !!!

Kind Regards

Hi @UiAl,

If you’re trying to get the month in 2 digit format, can you try the below code:

DateTime.Now.ToString(“MM”)

Here is a good reference to all the character codes for date formatting.
https://www.dotnetperls.com/datetime-format

Perfect!

Thank you!!!

Have a nice day!

1 Like

Thank you Heather!

1 Like