The following calculates the difference in seconds between two dates ([Date1],[Date2]) and two times ([Time1],[Time2]):

- Code: Select all
`.Convert time1 to seconds since midnight`

SubStr "[Time1]" "1" "2" "[H]"

SubStr "[Time1]" "4" "2" "[M]"

SubStr "[Time1]" "7" "2" "[S]"

Math "([H]*3600)+([M]*60)+[S]" "0" "[T1]"

.Convert time2 to seconds since midnight

SubStr "[Time2]" "1" "2" "[H]"

SubStr "[Time2]" "4" "2" "[M]"

SubStr "[Time2]" "7" "2" "[S]"

Math "([H]*3600)+([M]*60)+[S]" "0" "[T2]"

.Convert date1 to days

DateToNum "[Date1]" "m/d/y" "[D1]"

.Convert date2 to days

DateToNum "[Date2]" "m/d/y" "[D2]"

.subtract date2 from date1 and convert to seconds

Math "([D2]-[D1])*86400" "0" "[ElapsedDaysAsSeconds]"

.subtract time2 from time1

Math "[T2]-[T1]" "0" "[ElapsedSeconds]"

.combine elapsed days as seconds and seconds

Math "[ElapsedDaysAsSeconds]+[ElapsedSeconds]" "0" "[ElapsedTime]"

.display the results

AlertBox "Result" "Elapsed time is: [ElapsedTime] seconds"