Solved

DOS MMM Date Format

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

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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Being a system administrator some time we require to do things remotely, one of them is installing software. Here I am going to tell you how to install software through wmic (Windows management instrument console). I am not at all saying that this i…
Introduction: Recently, I got a requirement to zip all files individually with batch file script in Windows OS. I don't know much about scripting, but I searched Google and found a lot of examples and websites to complete my task. Finally, I was ab…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

820 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