dbareis said:
I found this "magic" a while back:
@echo off
@rem NEWSGROUP: microsoft.public.win2000.cmdprompt.admin
@rem SUBJECT : How can i to get the current month in commandline?
@rem WHEN/WHO : Mar 14 2001, 9:05 pm post by Michael (maj0)
:: Tokenise date into dd mm and yy independent of locale
for /f "tokens=2-4 delims=.:/-, " %%i in ("%date%") do (
for /f "tokens=2-4 delims=/-,() skip=1" %%l in ('echo.^|date') do (
set %%l=%%i
set %%m=%%j
set %%n=%%k))
:: Lets see what we got!
for %%i in (dd mm yy) do set %%i
Recently i've come somewhat interested in this topic, so i've
found this group and this discussion as well as the cmd-script
(a degree better then the one above) in the Microsoft FAQ:
http://www.microsoft.com/technet/prodtechnol/Windows2000serv/support/FAQW2KCP.mspx
However, it does not provide true locale independent solution too.
So i've spent last evening to create a more universal design.
This is primarily destined for non-English users. If someone is
interested in that, please test it.
The idea is based on the fact that "chcp 437" switches output
of the "date" command into English. That's true for Windows XP
with MUI pack. However, it appears to be not true for a fully
localized Windows 2000. For the latter case the script needs
some easy modification - see code below (actually, i did not
test it under other Windows versions).
--
@echo off
rem The commandline script creates locale independent
rem environment variables for current date and time.
rem This works under Windows XP with MUI pack al least.
rem
rem USAGE: this.cmd <Prefix>
rem
rem On return the following environment variables set:
rem <Prefix>.Y year number (00-99)
rem <Prefix>.M month number
rem <Prefix>.D day number
rem <Prefix>.H hour (00-23)
rem <Prefix>.N minute
rem <Prefix>.S second
rem <Prefix>.U hundredths of second
rem The values are always in the format of two digits.
:codepage_change
for /f "tokens=2 delims=:" %%a in ('chcp') do set z$zP=%%a
set z$zP=%z$zP: =%
if "%z$zP%"=="437" goto codepage_enu
if "%z$zP%"=="850" goto codepage_enu
chcp 437 >nul
goto time_boogie
:codepage_enu
set z$zP=
:time_boogie
for /f "tokens=2-5 delims=:/-,()." %%a in ('echo.^|time') do (
set z$zH=%%a
set z$zN=%%b
set z$zS=%%c
set z$zU=%%d
goto time_proof )
:time_proof
set z$zH=%z$zH: =%
if "%z$zH:~1%"=="" (
set %1.H=0%z$zH%
) else (
set %1.H=%z$zH%
)
rem set z$zN=%z$zN: =%
if "%z$zN:~1%"=="" (
set %1.N=0%z$zN%
) else (
set %1.N=%z$zN%
)
rem set z$zS=%z$zS: =%
if "%z$zS:~1%"=="" (
set %1.S=0%z$zS%
) else (
set %1.S=%z$zS%
)
set z$zU=%z$zU: =%
if "%z$zU:~1%"=="" (
set %1.U=0%z$zU%
) else (
set %1.U=%z$zU%
)
:time_cleanup
set z$zH=
set z$zN=
set z$zS=
set z$zU=
:time_finish
:date_boogie
for /f "tokens=1 delims=/.,\
" %%u in ('date /t') do set z$zD=%%u
if "%z$zD:~0,1%" GTR "9" ( set z$zT=2-4 ) else ( set z$zT=1-3 )
for /f "tokens=%z$zT% delims=/.,\
" %%u in ('date /t') do (
for /f "skip=1 tokens=2 delims=(" %%g in ('echo.^|date') do (
for /f "tokens=1-3 delims=/.,\
" %%x in ("%%g") do (
if "%%x"=="??" goto date_hard
set z$z%%x=%%u
set z$z%%y=%%v
set z$z%%z=%%w
)
)
)
:date_proof
if "%z$zyy:~3%"=="" (
if "%z$zyy:~1%"=="" (
set %1.Y=0%z$zyy%
) else (
set %1.Y=%z$zyy%
)
) else (
set %1.Y=%z$zyy:~2%
)
if "%z$zmm:~1%"=="" (
set %1.M=0%z$zmm%
) else (
set %1.M=%z$zmm%
)
if "%z$zdd:~1%"=="" (
set %1.D=0%z$zdd%
) else (
set %1.D=%z$zdd%
)
:date_cleanup
set z$zyy=
set z$zmm=
set z$zdd=
set z$zD=
set z$zT=
:date_finish
:codepage_restore
if not "%z$zP%"=="" (
chcp %z$zP% >nul
set z$zP=
)
goto end_boogie
rem The system appears to be unable to set code page 437
:date_hard
set z$z??=
:date_hard_codepage_restore
chcp %z$zP% >nul
:date_hard_boogie
for /f "tokens=1 delims=/.,\
" %%u in ('date /t') do set z$zD=%%u
if "%z$zD:~0,1%" GTR "9" ( set z$zT=2-4 ) else ( set z$zT=1-3 )
for /f "tokens=%z$zT% delims=/.,\
" %%u in ('date /t') do (
for /f "skip=1 tokens=2 delims=(" %%g in ('echo.^|date') do (
for /f "tokens=1-3 delims=/.,\
" %%x in ("%%g") do (
set z$z%%x=%%u
set z$z%%y=%%v
set z$z%%z=%%w
)
)
)
:date_hard_codepages_by_hand
if "%z$zP%"=="866" (
set z$zyy=%z$zгг%
set z$zmm=%z$zмм%
set z$zdd=%z$zдд%
set z$zгг=
set z$zмм=
set z$zдд=
goto date_proof
)
rem JUST ADD YOUR CODEPAGE HERE (CP_OEM)
if "%z$zP%"=="???" (
set z$zyy=%z$z??%
set z$zmm=%z$z??%
set z$zdd=%z$z??%
set z$z??=
set z$z??=
set z$z??=
goto date_proof
)
:date_hard_cleanup
set z$zyy=
set z$zmm=
set z$zdd=
set z$zD=
set z$zT=
echo BUMM !!! ADD YOUR CODEPAGE (%z$zP%), PLEASE
set z$zP=
:date_hard_finish
:end_boogie
rem set > set.txt
--