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


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 off
if \{%2\}==\{\} @echo Syntax: call mmm2MM mmm MM&goto :EOF
setlocal
set xxx=%1###
if "%xxx:~2,1%" EQU "#" @echo Syntax: call mmm2MM mmm MM&endlocal&set %2=00&goto :EOF
set mmm=XXX00
for %%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?



Hide comments

Comments

  • Allowed HTML tags: <em> <strong> <blockquote> <br> <p>

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
Publish