How much time is remaining?
Excel, 6 Bytes
=B1-A1
Assuming A is in cell A1
and B is in cell B1
MATL, 17 7 bytes
YOd15XO
Input is a cell array of strings, in the form {'1:45' '3:15'}
or {'1:45', '3:15'}
.
Try it online!
Explanation
YO % Input cell array of strings (implicit). Convert to serial date numbers
d % Difference
15XO % Convert to format 15, i.e. 'HH:MM'. Display (implicit)
Bash + coreutils, 44 39 bytes
tr : \ |dc -e?r60*+r-r60*-60~rn58PA~rnn
Try it online!
Explanation: using "1:45 3:15" as test case (last example). I show intermediary steps in quotes.
tr : \ | # replace colons with spaces: "1 45 3 15"
dc -e? # start dc script, push input to LIFO stack: "15 3 45 1"
r60*+ # turn time B to total seconds: "195 45 1"
r-r60*- # turn time A to total seconds and get difference: "90"
60~r # turn difference (time left) to minutes and seconds: "1 30"
n58P # pop and print minutes, print colon (ASCII code 58): "30"
A~rnn # print seconds. Padding with zeroes is done by dividing by
#10 (A), and printing the quotient and the remainder.
Note that I don't check if the minute value needs zero padding, because the OP stated that the maximum value for m
is 9.
Below is my original 44 bytes answer, that used the date
command to turn the total time left in seconds to the m:ss
format.
date -d@`tr : \ |dc -e?r60*+r-r60*-p` +%M:%S