JSI Tip 10273. How can I convert a month number to a 3 character month abbreviation?


I scripted MM2MMM.bat to convert a month number to a 3 character month abbreviation.

The MMtoMMM.bat script should be slightly faster if you intend to make many call to it.

The syntax for using MMtoMMM.bat is:

call MMtoMMM MM MMM

Where:

MM  is the month number, from 1 (or 01) through 12.

MMM is a call directed environment variable that will contain the 3 character month abbreviation.
MMtoMMM.bat contains:
@echo off
if \{%2\}==\{\} @echo Syntax: call MMtoMMM MM MMM&goto :EOF
if exist "%TEMP%\MMtoMMM.vbs" goto doit
@echo Dim objArguments>"%TEMP%\MMtoMMM.vbs"
@echo Set objArguments = Wscript.Arguments>>"%TEMP%\MMtoMMM.vbs"
@echo Months = Array("Unk", "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec")>>"%TEMP%\MMtoMMM.vbs"
@echo Wscript.Echo Months(objArguments(0))>>"%TEMP%\MMtoMMM.vbs"
:doit
if \{%1\} GTR \{12\} set %2=Unk&goto :EOF
for /f "Tokens=*" %%m in ('cscript //nologo "%TEMP%\MMtoMMM.vbs" %1') do (
 set %2=%%m
)



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