We help IT Professionals succeed at work.

Batch File: Add seconds

ReneGe
ReneGe asked
on
Hi there,

BillPrew recently did this batch file for me.

I would now like to add seconds to it.

Reference:
http://www.experts-exchange.com/OS/Microsoft_Operating_Systems/MS_DOS/Q_27476219.html#a37231426

Thanks,
Rene
@echo off
setlocal

set SpeedInKM=120
set KMtoGo=157

for /F "tokens=1,2" %%A in ('WMIC Path Win32_LocalTime Get Hour^,Minute ^| FINDSTR /R [0123456789]') do (
  set EndHour=%%A
  set EndMinute=%%B
)
call :DisplayTime "Start Time" %EndHour% %EndMinute%

set /A Hours=KMtoGo / SpeedInKM
set /A Minutes=(60 * (KMtoGo - (Hours * SpeedInKM))) / SpeedInKM
call :DisplayTime "Elapsed time" %Hours% %Minutes%

set /A EndHour=(EndHour + Hours + ((EndMinute + Minutes) / 60)) %% 24
set /A EndMinute=(EndMinute + Minutes) %% 60
call :DisplayTime "Arrive Time" %EndHour% %EndMinute%

pause
exit /b

:DisplayTime [heading] [hour] [minute]
  set "_h=0%~2" & set "_m=0%~3"
  echo %~1 = %_h:~-2%:%_m:~-2%
  exit /b

Open in new window

Comment
Watch Question

Test your restores, not your backups...
Expert of the Year 2019
Top Expert 2016
Commented:
Give this a try Rene.

@echo off
setlocal

set SpeedInKM=120
set KMtoGo=157

for /F "tokens=1-3" %%A in ('WMIC Path Win32_LocalTime Get Hour^,Minute^,Second ^| FINDSTR /R [0123456789]') do (
  set EndHour=%%A
  set EndMinute=%%B
  set EndSecond=%%C
)
call :DisplayTime "Start Time" %EndHour% %EndMinute% %EndSecond%

set Remain=%KMtoGo% 
set /A Hours=Remain / SpeedInKM
set /A Remain=Remain - (Hours * SpeedInKM)
set /A Minutes=Remain * 60 / SpeedInKM
set /A Remain=Remain - (Minutes * SpeedInKM / 60)
set /A Seconds=Remain * 3600 / SpeedInKM
set /A Remain=Remain - (Seconds * SpeedInKM / 3600)
call :DisplayTime "Elapsed time" %Hours% %Minutes%  %Seconds%

set /A EndHour=(EndHour + Hours + ((EndMinute + Minutes) / 60)) %% 24
set /A EndMinute=(EndMinute + Minutes + ((EndSecond + Seconds) / 60)) %% 60
set /A EndSecond=(EndSecond + Seconds) %% 60
call :DisplayTime "Arrive Time" %EndHour% %EndMinute% %EndSecond%

pause
exit /b

:DisplayTime [heading] [hour] [minute] [second]
  set "_h=0%~2" & set "_m=0%~3" & set "_s=0%~4"
  echo %~1 = %_h:~-2%:%_m:~-2%:%_s:~-2%
  exit /b

Open in new window

~bp

Commented:
Show off ;)
Bill PrewTest your restores, not your backups...
Expert of the Year 2019
Top Expert 2016

Commented:
:-)

Author

Commented:
Thanks Bill for showing off ;)