You cannot format an integer variable, you need to use a string variable to format it.
You can convert the day part of the date to leading zeros using the Day function to extract the day number from the date, and then use the Format function with the "00" format to add leading zero if necessary
Format (day (myDate), "00")
myDate is a Date variable containing the full date value
The following macro can be used as a working sample.
Sub Macro1() Dim myDate As Date myDate = "2015-5-1" Dim dayPart As String dayPart = Format(Day(myDate), "00") MsgBox dayPart End Sub
source share