JSI Tip 7046. How do I convert a 3 character month abbreviation to a 2 digit month number string?

Jerold Schulman

August 10, 2003

1 Min Read
ITPro Today logo in a gray background | ITPro Today


I have scripted mmm2MM.bat to convert a 3 character English month abbreviation to a 2 digit month number string.

The syntax for using mmm2MM.bat is:

call mmm2MMM mmm MM

where mmm is the 3 character month abbreviation and MM is the call directed environment variable that will contain the 2 digit month number string, or 00 if the month abbreviation is not found.

mmm2MM.bat contains:

@echo offif {%2}=={} @echo Syntax: call mmm2MM mmm MM&goto :EOFsetlocalset xxx=%1###if "%xxx:~2,1%" EQU "#" @echo Syntax: call mmm2MM mmm MM&endlocal&set %2=00&goto :EOFset mmm=XXX00for %%a in (JAN01 FEB02 MAR03 APR04 MAY05 JUN06 JUL07 AUG08 SEP09 OCT10 NOV11 DEC12) do ( for /f %%b in ('@echo %%a^|findstr /i /l /c:%1') do call set mmm=%%b)endlocal&set %2=%mmm:~3,2%

NOTE: See tip 6837 How do I convert the current month to an environment variable containing a 3 character month abbreviation?



Sign up for the ITPro Today newsletter
Stay on top of the IT universe with commentary, news analysis, how-to's, and tips delivered to your inbox daily.

You May Also Like