Dos - How to convert Month name as Numbers -

June 29, 2011 at 09:11:54
Specs: Windows 7
Hi,

I want to capture the current date in the format - Month-Day-Year (6-29-11).
Date gives output as 29-Jun-11 and I am modifying as below.

set month=%date:~3,3%
set Day=%date:~0,2%
set year=%date:~7,3%

if %month%==Jan set cmonth=1
if %month%==Feb set cmonth=2
if %month%==Mar set cmonth=3
if %month%==Apr set cmonth=4
if %month%==May set cmonth=5
if %month%==Jun set cmonth=6
if %month%==Jul set cmonth=7
if %month%==Aug set cmonth=8
if %month%==Sep set cmonth=9
if %month%==Oct set cmonth=10
if %month%==Nov set cmonth=11
if %month%==Dev set cmonth=12

Is there any way we can convert the months as numbers ??


See More: Dos - How to convert Month name as Numbers -

Report •


#1
June 30, 2011 at 02:26:22
Test this... Assumes your current date format is dd/mmm/yy

@echo off
cls
setlocal enabledelayedexpansion

set month=%date:~3,3%
set Day=%date:~0,2%
set year=%date:~7,2%

set nbr=0
for %%1 in (Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec) do (
  set /a nbr+=1
  echo %month%|findstr /i /b "%%1" >nul&& goto finis
)

:finis
if %nbr% lss 10 set nbr=0%nbr%

echo.&echo.
echo The month of %month% is month number %nbr%
echo.
echo Current date = %nbr%-%day%-%year% 


Please come back & tell us if your problem is resolved.


Report •
Related Solutions


Ask Question