@echo off
cls
:: ------------------------------------------------------
:: FORATIM2.BAT batch file
::
:: FUNCTION
:: Calculate the elapsed time (in days and minutes)
:: between some "begin" date/time and some "end" date/time
::
:: ------------------------------------------------------
echo --------------------------------------------------------------
echo Calculate elapsed time between two date/times
echo --------------------------------------------------------------
:BegDate
Fdate /Fget /VBEGdate /Q"Enter BEGIN DATE (mm-dd-ccyy): "
if (%BegDate%)==() goto Cleanup
:BegTime
Fdate /Fget /VBEGtime /Q"Enter BEGIN TIME (hh:mm).....: "
if (%BegTime%)==() goto Cleanup
:: validate date & time
Fdate /fv /A%BEGdate% /T%BEGtime% >nul
if errorlevel 1 echo Invalid date/time
if errorlevel 1 goto BegDate
:: get absolute minute of start date/time.
Fdate /Ff /ominute# /A%BEGdate% /T%BEGtime% /VABStime1
if errorlevel 1 goto BegTime
Fdate /Ff /Ofull /A%BEGdate% /T%BEGtime% /Vfull1
::
echo.
:EndDate
Fdate /Fget /VENDdate /Q"Enter END.. DATE (mm-dd-ccyy): "
if (%EndDate%)==() goto Cleanup
:EndTime
Fdate /Fget /VENDtime /Q"Enter END.. TIME (hh:mm).....: "
if (%EndTime%)==() goto Cleanup
:: validate date & time
Fdate /fv /A%ENDdate% /T%ENDtime% >nul
if errorlevel 1 echo Invalid date/time
if errorlevel 1 goto EndDate
:: get absolute minute of end date/time.
Fdate /Ff /ominute# /A%ENDdate% /T%ENDtime% /VABStime2
if errorlevel 1 goto EndTime
Fdate /Ff /Ofull /A%ENDdate% /T%ENDtime% /Vfull2
echo.
echo Calculating elapsed time...
:: calculate the difference between ABStime1 and ABStime2
Fdate /f#dif /A%ABStime1% /B%ABStime2% /VMinutes
:: calculate the number of hours in it took
Fdate /f#Idiv /A%minutes% /B60 /VHours
:: calculate the number of extra minutes it took
Fdate /f#mod /A%minutes% /B60 /VMins
echo.
echo Between %full1%
echo and %full2%
echo.
echo Elapsed time was:
echo %hours% hours and %mins% minutes
Fdate /f#Idiv /A%minutes% /B1440 /Vday1
Fdate /f#mod /A%minutes% /B1440 /Vmin1
Fdate /f#Idiv /A%min1% /B60 /Vhour1
Fdate /f#mod /A%min1% /B60 /Vmin2
echo or
echo %day1% day(s) %hour1% hour(s) and %min2% minute(s).
echo.
echo.
:cleanup
set ENDdate=
set BEGdate=
set BEGtime=
set ENDtime=
set full1=
set full2=
set minutes=
set ABStime1=
set ABStime2=
set day1=
set hour1=
set min1=
set min2=
set mins=
set hours=
:endit