Format date number to 2 digits: 01, 02, 03, ... 09, 10 etc

Jonathan Grover's icon

I am using the [date] object to name recordings made in a Max patch according to the time and date they were recorded. Since, I am sorting these recordings in numeric order unfortunately the number 2 for example will show up after the number 11 even though it was recorded earlier. I need to reformat the number 2 to the number 02 instead. That way 02 sorts before 11 as it should! I tried [sprintf] and other text number formatting, but a zero on the front of a number always disappears! help please.

Max Patch
Copy patch and select New From Clipboard in Max.

here is an example patch:

pid's icon
Max Patch
Copy patch and select New From Clipboard in Max.

if you had read the help file of sprintf you wuld have discovered the easy way to add leading zeros:

Jonathan Grover's icon

Thanks pid! I noticed that this only works if you add a letter before the zero. That why it didn't work for me earlier.

Anyway to remove the letter and keep the zero?

I would like my dates to look clean without extra characters if possible.

Max Patch
Copy patch and select New From Clipboard in Max.

See edited pid patch:

pid's icon

ah i see.

Max Patch
Copy patch and select New From Clipboard in Max.

[combine] then...