Solved

DOS MMM Date Format

Posted on 2004-10-19
4
1,563 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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

The following is a collection of cases for strange behaviour when using advanced techniques in DOS batch files. You should have some basic experience in batch "programming", as I'm assuming some knowledge and not further explain the basics. For some…
One of my most closely kept secrets is revealed in this discussion How to output text on the same line This question was recently posted in EE by Simon336697 (http://www.experts-exchange.com/Programming/Languages/Scripting/Shell/Batch/Q_2459…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

747 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

10 Experts available now in Live!

Get 1:1 Help Now