Assume that a reporting date is passed in that does not have leading zeros for the date month part. Normally it is passed in as param1 but below I am forcing a value for this example.
I would like to construct a string where teh month and year are extracted from the date that is passed in and construct a string in the format YYYY_MM where MM has leading zeros.
REM SET ReportingDate=%1
SET ReportingDate=7/31/2011
@For /F "tokens=1,2,3 delims=/ " %%A in ("%ReportingDate%") do @(
Set Month=%%A
Set Day=%%B
Set Year=%%C
)
echo Year=%Year%
echo Month=%Month%
SET NewFileName=MEMBOB_%Year%_%Month%.csv
Q: My knowledge of batch files is limited. What do I have do do to force a leading zero in the montgh when the date month is 1 digit long?
Use an if-statement to prepend a 0 if the month is less than 10: