Solved

DOS MMM Date Format

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

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

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

Suggested Solutions

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…
TOMORROW TOMORROW.BAT is inspired by a question I get asked over and over again; that is, "How can I use batch file commands to obtain tomorrow's date?" The crux of this batch file revolves around the XCOPY command - a technique I discovered w…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

809 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