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


NOTE: see tip 10273 ยป How can I convert a month number to a 3 character month abbreviation?

In tip 6837, we converted the current month to a 3 character month abbreviation.

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

The syntax for using MM2MMM.bat is:

call MM2MMM 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.
NOTE: See How do I convert a date to the day number and day name?

MM2MMM.bat contains:

@echo off
if \{%2\}==\{\} @echo Syntax: call MM2MMM MM MMM&goto :EOF
setlocal
set montab=UNKJANFEBMARAPRMAYJUNJULAUGSEPOCTNOVDEC
set /a MMO=0
if %1 EQU +%1 set /a MMO=(100%1%%100) * 3
if %MMO% GTR 36 set /a MMO=0
call set MMM=%%montab:~%MMO%^,3%%
endlocal&set %2=%MMM%



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