Here the last improved version: http://www.dostips.com/forum/viewtopic.php?p=29758#p29758
getdate.cmd
Code: Select all
:getdate
set /a "jan=1,feb=2,mar=3,apr=4,may=5,jun=6,jul=7,aug=8,sep=9,oct=10,nov=11,dec=12"
set /a "mon=1,tue=2,wed=3,thu=4,fri=5,sat=6,sun=7"
set "tf=%temp%\~%random%"
copy /y nul "%tf%.foo" >nul 2>&1
if errorlevel 1 goto :getdate
makecab /l "%temp%" /d rptfilename="%tf%.rpt" /d inffilename=nul /f "%tf%.foo" >nul 2>&1
if errorlevel 1 goto :getdate
set /p "timestamp=" <"%tf%.rpt" >nul 2>&1
if errorlevel 1 goto :getdate
for /f "tokens=3-9 delims=: " %%a in ("%timestamp%") do (
set /a "year=%%g,month=%%b,day=1%%c-100,weekday=%%a"
set /a "hour=1%%d-100,minute=1%%e-100,second=1%%f-100"
)
for %%a in ("%tf%.rpt","%tf%.foo") do if exist "%%~a" del "%%~a" 2>nul
goto :eof