Prefix Day Or Month With Zero If required

Often we want to have the date presented as a fixed length string, e.g. for the purpose of sorting files: 20240302 instead of 202432. For this purpose we can use


Format(dat, "yyyymmdd")

If we don't have a date as input, but need to construct it from a year, month and day, then we can do:


yr & Format(mnth,"00") &  Format(day,"00")

str = Format(i,"00") 

i = 5 >> str = "05"

i = 25 >> str = "25"