I'll implement the registry method into Antonios code
Code: Select all
@echo off
setlocal
call :DateToJDN "%date%" jdn=
set /A minus90=jdn-90, minus180=jdn-180
call :JDNtoDate %minus90% minus90=
call :JDNtoDate %minus180% minus180=
echo Today minus 90 days: %minus90%, minus 180 days: %minus180%
pause
goto :EOF
:DateToJDN locale_date_format jdn=
setlocal
set "date=%~1"
for /f "tokens=1,2*" %%a in ('reg query "HKCU\Control Panel\International"^|findstr /i "\<[is]Date\>"') do set "%%a=%%c"
for /f "tokens=1-3 delims=%sDate%" %%a in ("%date:* =%") do (
if %iDate%==0 (set /a mm=100%%a%%100,dd=100%%b%%100,yyyy=10000%%c%%10000) else (
if %iDate%==1 (set /a dd=100%%a%%100,mm=100%%b%%100,yyyy=10000%%c%%10000) else (
if %iDate%==2 (set /a yyyy=10000%%a%%10000,mm=100%%b%%100,dd=100%%c%%100)
)))
if %yyyy% LSS 100 if %yyyy% LSS 70 (set /a yyyy=2000+yyyy) else (set yyyy=1900+yyyy)
set /A a=(mm-14)/12, jdn=(1461*(yyyy+4800+a))/4+(367*(mm-2-12*a))/12-(3*((yyyy+4900+a)/100))/4+dd-32075
endlocal & set %2=%jdn%
exit /B
:JDNtoDate jdn yyyymmdd=
setlocal
set /A l=%1+68569,n=(4*l)/146097,l=l-(146097*n+3)/4,i=(4000*(l+1))/1461001,l=l-(1461*i)/4+31,j=(80*l)/2447
set /A dd=l-(2447*j)/80,l=j/11,mm=j+2-(12*l),yyyy=100*(n-49)+i+l
if %dd% lss 10 set dd=0%dd%
if %mm% lss 10 set mm=0%mm%
endlocal & set %2=%yyyy%%mm%%dd%
exit /B
Regards
aGerman