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

Jerold Schulman

March 14, 2006

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


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 offif {%2}=={} @echo Syntax: call MMtoMMM MM MMM&goto :EOFif 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":doitif {%1} GTR {12} set %2=Unk&goto :EOFfor /f "Tokens=*" %%m in ('cscript //nologo "%TEMP%MMtoMMM.vbs" %1') do ( set %2=%%m)



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