Here's a nearly bullet-proof solution, now with a basic validity test of the user's input:
@ECHO OFF >NUL
:loopStartTime
set "startTime=%time:~0,5%"
echo Need Task Start Time in 24 hour format
echo (example 14:00 for 2pm, 08:00 for 8am)
set /p "startTime=Please enter Start Time (default=%StartTime: =%) "
::: test user's input and force repeat in case of extra serious error
::: e.g. mistyped `09/00` or `09%00` or `09<00` etc. instead of `09:00`
set "_val_test=%startTime: =%"
set /A "_val_test=1%_val_test::=+%" || goto :loopStartTime
::: format startTime to become a valid valid time in HH:mm (24 hours) pattern
call :addminutes startTime "%startTime: =%" 0
::: previous call with "quoted" 2nd parameter as user's input might contain
::: a valid parameter delimiter, i.e. one or more from commonly used
::: Comma `,` Semicolon `;` Equals `=` Space ` ` Tab ` `
echo schtasks /create /tn "Task1" /sc DAILY /st %StartTime% /tr "Task 1"
call :addminutes startTim2 %startTime% 1
echo schtasks /create /tn "Task2" /sc DAILY /st %StartTim2% /tr "Task 2"
goto :eof
:addminutes
:::::::::::::::::::::::::::::::::::::::::::::::::::
::: %1 (byref, obligatory) output variable name
::: %2 (byval, optional) valid time HH:mm (24 hours)
::: %3 (byval, optional) minutes to add
:::::::::::::::::::::::::::::::::::::::::::::::::::
SETLOCAL enableextensions disabledelayedexpansion
set "sTime=%~2"
set /A "sPlus=100%~3%%100" 2>nul
for /F "tokens=1-2 delims=:. " %%a in ("%sTime%") do (
set /A "timeHour=100%%a%%100" 2>nul
set /A "timeMinute=100%%b%%100" 2>nul
)
::: Convert HH:MM to minutes + %3
set /A "newTime=(timeHour*60)+timeMinute+sPlus"
::: Convert new time back to HH:MM
set /A "timeHour=newTime/60%%24"
set /A "timeMinute=newTime%%60"
::: Adjust new hour, minute and return value
set "timeHour=00%timeHour%"
set "timeMinute=00%timeMinute%"
set "sTime=%timeHour:~-2%:%timeMinute:~-2%"
::: do not change next line
ENDLOCAL&set "%~1=%sTime%"&goto :eof
Note. An user can input almost anything in response to set /P; output from the :addminutes procedure always results to a valid time in HH:mm (24 hours) pattern, e.g.
<Enter> results to current time, cf. initial set "startTime=%time:~0,5%"
15 results to 15:00
9:9 results to 09:09
any nonsens results to 00:00
Edit: more comments in the code
:addminutes procedure based on Aacini's answer
"%time%"referenced there use"%startTime%"and omit that seconds.