Solved

DOS MMM Date Format

Posted on 2004-10-19
4
1,592 Views
Last Modified: 2008-03-03
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?
0
Comment
Question by:jasonboetcher
  • 2
4 Comments
 
LVL 95

Accepted Solution

by:
Lee W, MVP earned 250 total points
ID: 12351237
The following script will set the variable "mmm" to the month name (3 character) format.

@echo off
for /f "tokens=2 delims=/ " %%a in ('date /t') do (
if "%%a" == "1" set mmm="JAN"
if "%%a" == "2" set mmm="FEB"
if "%%a" == "3" set mmm="MAR"
if "%%a" == "4" set mmm="APR"
if "%%a" == "5" set mmm="MAY"
if "%%a" == "6" set mmm="JUN"
if "%%a" == "7" set mmm="JUL"
if "%%a" == "8" set mmm="AUG"
if "%%a" == "9" set mmm="SEP"
if "%%a" == "10" set mmm="OCT"
if "%%a" == "11" set mmm="NOV"
if "%%a" == "12" set mmm="DEC"
)
0
 
LVL 5

Expert Comment

by:brianadkins
ID: 12351262

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
0
 
LVL 5

Expert Comment

by:brianadkins
ID: 12351274
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
0
 
LVL 83

Expert Comment

by:oBdA
ID: 12352023
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%]
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Using dates in 'DOS' batch files has always been tricky as it has no built in ways of extracting date information.  There are many tricks using string manipulation to pull out parts of the %date% variable or output of the date /t command but these r…
VALIDATING DATES One method of validating dates is to jam the date into the DATE command and see if it accepts it by examining the system's errorlevel value. A non-zero result indicates failure. A typical example might look something like the fol…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

919 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now