Creating a batch that sets time/date ahead 33 days possible?

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Message
Author
serverdelux
Posts: 36
Joined: 04 Oct 2013 14:14

Re: Creating a batch that sets time/date ahead 33 days possi

#16 Post by serverdelux » 10 Oct 2013 16:33

Was working with this code that was given to me here and noticed that the two console windows behave differently when an invalid option is entered

The first :mainmenu when a non-valid option is entered like C then screen jumps and resets
The second :loop2 does not jump and stays if non-valid option is entered

How can I convert the first way into the second way with the possiblilty of having many options like A, B, C, D, E, etc...

The second just seems smoother :mrgreen:

Code: Select all

@echo off
color 3d
title DateTest
mode con: cols=44 lines=7

:mainmenu
mode con: cols=44 lines=7
echo.
echo Date Test
echo.
echo.A. Set date ahead 33 days?
echo.B. Exit
echo.

set userinp=

set /p userinp=    ^   Make your selection:
set userinp=%userinp:~0,1%
if /i "%userinp%"=="A" goto A
if /i "%userinp%"=="B" goto exit
GOTO :mainmenu


:A
cls
mode con: cols=44 lines=7
setlocal EnableDelayedExpansion
for /f "tokens=1,2*" %%a in ('reg query "HKCU\Control Panel\International"^|findstr /i "\<[is]Date\>"') do set "%%a=%%c"

call :DaysAdd 33 newDate
date %newDate%
echo(
:loop2
echo New date: %date%
echo(


echo Would you like to correctly reset the date?
echo(
echo A. Yes
echo.
set /p "c=Make your selection: "
if /i "!c!" neq "A" cls & goto loop2
call :DaysAdd -33 newDate
date %newDate%
goto :mainmenu

:DaysAdd ByVal_DeltaIn  ByRef_NewDateOut
setlocal
for /f "tokens=1-3 delims=%sDate%" %%a in ("%date:* =%") do (
  if %iDate%==0 (set /a Month=100%%a%%100,Day=100%%b%%100,Year=10000%%c%%10000) else (
  if %iDate%==1 (set /a Day=100%%a%%100,Month=100%%b%%100,Year=10000%%c%%10000) else (
  if %iDate%==2 (set /a Year=10000%%a%%10000,Month=100%%b%%100,Day=100%%c%%100)
)))
set /a "a = 14 - Month, a /= 12, b = Year + 4800 - a, c = Month + 12 * a - 3, d = 153 * c + 2"
set /a "d = d / 5 + Day + b * 365 + b / 4 - b / 100 + b / 400 - 1 + %~1"
set /a "e = 4 * d + 3, e /= 146097, f = -e * 146097, f /= 4, f += d"
set /a "g = 4 * f + 3, g /= 1461, h = -1461 * g, h /= 4, h += f, i = 5 * h + 2, i /= 153, Day = 153 * i + 2, Day /= 5"
set /a "Day = -Day + h + 1, Month = -i / 10, Month *= 12, Month += i + 3, Year = e * 100 + g - 4800 + i / 10"
set /a "Month = 10%Month%, Day = 10%Day%"
if %iDate%==0 (set "new=%Month:~-2%%sDate%%Day:~-2%%sDate%%Year%") else (
if %iDate%==1 (set "new=%Day:~-2%%sDate%%Month:~-2%%sDate%%Year%") else (
if %iDate%==2 (set "new=%Year%%sDate%%Month:~-2%%sDate%%Day:~-2%")))
endlocal &set "%~2=%new%" &goto:eof



:EXIT
ENDLOCAL
exit

Post Reply