Link to home
Start Free TrialLog in
Avatar of jasonboetcher
jasonboetcher

asked on

DOS MMM Date Format

How can I assign a variable to have the MMM format of the current date; ie set the value of variable to OCT if the current date is 10/19/2004?
ASKER CERTIFIED SOLUTION
Avatar of Lee W, MVP
Lee W, MVP
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial

something like this?

set MMMnum=%date:~4,2%
if MMMnum==01 set MMM=JAN
if MMMnum==02 set MMM=FEB
if MMMnum==03 set MMM=MAR
if MMMnum==04 set MMM=APR
if MMMnum==05 set MMM=MAY
if MMMnum==06 set MMM=JUN
if MMMnum==07 set MMM=JUL
if MMMnum==08 set MMM=AUG
if MMMnum==09 set MMM=SEP
if MMMnum==10 set MMM=OCT
if MMMnum==11 set MMM=NOV
if MMMnum==12 set MMM=DEC

-Brian
D'oh!... you beat me to it.

... plus I left off the percent signs around my variables

MMMnum should be %MMMnum% in lines 2+

-Brian
Avatar of oBdA
oBdA

A different version, which runs on W2k, XP and W2k3 (the %date% format differs; thanks, MS). If this needs to run on a single OS, another line could be removed.

@echo off
setlocal enabledelayedexpansion
for %%a in (%Date%) do set DateOnly=%%a
for /f "tokens=1 delims=/" %%a in ("%DateOnly%") do set Month=%%a
set i=0
for %%a in (Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec) do (
  set /a i+=1
  if !i!==%Month% set Month=%%a
)
echo Current Month: [%Month%]