batch file - Store date in DD-MMM-YYYY format -
i trying today's date in dd-mmm-yyyy format (for example, 12-jun-2015) can download file ftp server created daily.
i m using
@echo off set month-num=%date:~3,2% if "%month-num:~0,1%"=="0" set month-num=%month-num:~1% /f "tokens=%month-num%" %%a in ("jan feb mar apr may jun jul aug sep oct nov dec") set mo-name=%%a echo %mo-name%
it giving syntax error
i appreciate advice, have no idea begin.
ganesh, use of for /f
loop convert numeric month abbreviation pretty clever. think part of problem whoever wrote code you're using wrote their locale, not yours. %date%
looks different original author looks you.
the format of %date%
unpredictable (well, without complicated registry queries , conversions anyway). obtain datetime in locale agnostic way, it's easier use wmic os localdatetime
.
try this:
@echo off setlocal /f %%i in ('wmic os localdatetime /format:list ^| find "="') set "%%i" set "yyyy=%localdatetime:~0,4%" set /a "mm=1%localdatetime:~4,2% - 100" set "dd=%localdatetime:~6,2%" /f "tokens=%mm%" %%i in ("jan feb mar apr may jun jul aug sep oct nov dec") set "month=%%i" echo %dd%-%month%-%yyyy%
Comments
Post a Comment