Extracting MMM from the system date

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi, I am trying to extract "NOV" using these commands. But I am unable to
pass the value to %mmm%. I am novice in this feild so I have constructed
these lines using the news groups. Can some one advise me.

set month=%date:~4,2%
set monstring=XXXJANFEBMARJUNJULAUGSEPOCTNOVDEC
set /a mm=(100%month%%%100)*3
set mmm=%%monstring:~%mm%^,3%%
 
=?Utf-8?B?R2Fsb3A=?= said:
Hi, I am trying to extract "NOV" using these commands. But I am unable to
pass the value to %mmm%. I am novice in this feild so I have constructed
these lines using the news groups. Can some one advise me.

set month=%date:~4,2%
set monstring=XXXJANFEBMARJUNJULAUGSEPOCTNOVDEC
set /a mm=(100%month%%%100)*3
set mmm=%%monstring:~%mm%^,3%%

You want to fool us?
I'd include the missing APRMAY. If you subtract 3 from the offset there
is no need to patch with xxx. Parsing with for eases changes (for us
europeans)

::MonthName.cmd::::::::::::::::::::::::::::::::::::::::::::::::::::::
@echo off
setlocal EnableDelayedExpansion
for /F "tokens=1-4 delims=.-/ " %%A in ("%DATE%") do set month=%%B
set monstring=JANFEBMARAPRMAYJUNJULAUGSEPOCTNOVDEC
set /a mm=(100%month%%%100)*3-3
:: Use a call to get %mm% evaluated first.
call set mmm=%%monstring:~%mm%,3%%
echo Monthname=%mmm%
:: Or DelayedExpansion
set mmm2=!monstring:~%mm%,3!
echo Monthname2=%mmm2%
::MonthName.cmd::::::::::::::::::::::::::::::::::::::::::::::::::::::

HTH
 
Galop said:
Hi, I am trying to extract "NOV" using these commands. But I am unable to
pass the value to %mmm%. I am novice in this feild so I have constructed
these lines using the news groups. Can some one advise me.

set month=%date:~4,2%
set monstring=XXXJANFEBMARJUNJULAUGSEPOCTNOVDEC
set /a mm=(100%month%%%100)*3
set mmm=%%monstring:~%mm%^,3%%

=====begin C:\cmd\demo\FindThisMonth.cmd ====================
1. set months=Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec
2. set /a mm=1%date:~4,2%-100
3. for /f "tokens=%mm%" %%a in (
4. "%months%"
5. ) do echo this month is %%a
=====end C:\cmd\demo\FindThisMonth.cmd ====================
 
Galop said:
Hi, I am trying to extract "NOV" using these commands. But I am unable to
pass the value to %mmm%. I am novice in this feild so I have constructed
these lines using the news groups. Can some one advise me.

set month=%date:~4,2%
set monstring=XXXJANFEBMARJUNJULAUGSEPOCTNOVDEC
set /a mm=(100%month%%%100)*3
set mmm=%%monstring:~%mm%^,3%%
Hi

A combined batch/vbs solution, will work regardless of
regional settings:

--------------------8<----------------------
@echo off
echo D = Now : MN = MonthName(Month(D), True) : WScript.Echo MN >%tmp%\mn.vbs
for /f "tokens=*" %%a in (
'cscript.exe //Nologo %tmp%\mn.vbs') do set mmm=%%a
del %tmp%\mn.vbs
echo This month is %mmm%
--------------------8<----------------------
 
Back
Top