[Question]
  [
# The Program
You are given two strings, **A** and **B**. **A** is the current position at which your timer is at, and **B** is the position at which your timer will stop. Both strings are in the format **m:ss**. You must write a program that determines the amount of time left which should also be formatted as **m:ss** or **mm:ss**.
# Example
```
0:00 0:01 -> 0:01
0:55 1:00 -> 0:05
1:45 3:15 -> 1:30
```
  
[Answer]
# Excel, 6 Bytes
```
=B1-A1
```
Assuming A is in cell `A1` and B is in cell `B1`
[Answer]
# [MATL](https://github.com/lmendo/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!](https://tio.run/nexus/matl#@x/pn2JoGuH//3@1uqGViam6grqxlaGpei0A "MATL – TIO Nexus")
### 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)
```
[Answer]
## [Bash](https://www.gnu.org/software/bash/) + coreutils, ~~44~~  39 bytes
```
tr : \ |dc -e?r60*+r-r60*-60~rn58PA~rnn
```
**[Try it online!](https://tio.run/nexus/bash#@19SpGClEKNQk5KsoJtqX2RmoKVdpAuidM0M6oryTC0CHIFU3v//hlYmpgrGVoamAA)**
**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
```
[Answer]
# Python 2, ~~90~~ ~~87~~ ~~83~~ 80 bytes
Takes input like `"2:45","5:01"`.
```
a,b=[60*int(s[-5:-3])+int(s[-2:])for s in input()]
print'%d:%02d'%divmod(b-a,60)
```
[**Try it online**](https://tio.run/nexus/python2#@5@ok2QbbWaglZlXolEcrWtqpWscq6kN5RlZxWqm5RcpFCtk5gFRQWmJhmYsV0ERUFpdNcVK1cAoBUhnluXmp2gk6SbqmBlo/v@vZGRlYqqko2RqZWCoBAA)
[Answer]
# c, 86
```
f(a,b,c,d){scanf("%d:%d%d:%d",&a,&b,&c,&d);d+=(c-a)*60-b;printf("%d:%02d",d/60,d%60);}
```
Reads space-separated times from STDIN.
[Try it online](https://tio.run/nexus/c-gcc#fYpBCsMgFET3nkIERdsf@m2rC6WHUT9CFg2hSVchZ7cSsu4shnkz06pOkKEAmW0paapaSAqSDhOgEqgMqoAiE@n60mVI5uJxyHH@jNN63vHev3TzCCQ9mri3vvF3Gidt2MZ4V9UmHmH@rosW4qR/9d4wIPJulmFwjtuOzIan449g3Q8).
[Answer]
## Batch, 74 bytes
```
@set t=%2-(%1)
@set/as=%t::=*60+1%,m=s/60,t=s/10%%6
@echo %m%:%t%%s:~-1%
```
Replacing the `:` in the time with `*60+1` converts it into an expression that calculates the number of seconds. Batch interprets leading zeros as octal so I prepend a `1` to the seconds to ensure decimal conversion; fortunately the two `1`s cancel out.
[Answer]
# C, ~~112~~ 100 bytes
*Thanks to @betseg for saving 11 bytes and thanks to @Johan du Toit for saving one byte!*
```
i,j;f(char*a,char*b){i=atoi(b)-atoi(a);j=atoi(b+2)-atoi(a+2);j<0?i--,j+=60:0;printf("%d:%02d",i,j);}
```
[Try it online!](https://tio.run/nexus/c-gcc#XYzBCsIwEETvfkagkLUJJNV4yFr8ltRS3IC11Hgq/fa4qXrxNMN7w2RSEQd5vYV5H9QWHSzUhvQg2YHeMgDGL6mbH@OG8WwupLWKdXsy3uA005gGKareV6bpheJ3wDXfA40Slh0rnhmhSlgBOL3SUwouH@UcK1sWf8r6Y1EHb10ha34D)
[Answer]
# MySQL, ~~13~~ 22 bytes
```
select right(timediff(B,A),5)
```
expects the times in `A` and `B`.
[Answer]
# Bash + GNU utilities, 43
```
date -d@`date -f- +%s|dc -e??r-60/p` +%M:%S
```
[Try it online](https://tio.run/nexus/bash#PYyxCsMgFEX3fsVFIhmKVGntYIb0Bzp1zZAQn5BFgzrm3@0rgd7hcDjDDSmjUqnrUghbhNBOazCM@Lm1MBzYjXtY3J2xYoBPF/D2vMUa0MsyxR7d/@bA1PxSCcq/5lOCwlWWw69QNI5ZPfVtnzm9nfw0nyK1Lw).
### Explanation
```
         date -f- +%s                        # read in 2 line-delimited dates and output as number of seconds since the epoch
                     |dc -e                  # pipe to dc expression:
                           ??                # - read 2 input numbers
                             r-              # - reverse and subtract
                               60/           # - divide by 60
                                  p          # - output
        `                          `         # evaluate date|dc command
date -d@                             +%M:%S  # format seconds difference and output
```
Note the `dc` expression divides by 60, because `date` reads the input as H:MM instead of M:SS.
[Answer]
# ECMAScript 6, 99 91 85 bytes
## Single Line:
```
f=s=>s.split`:`.reduce((a,e,i)=>a+e*(!i?60:1),0);t=n=>~~(n/60)+":"+n%60;t(f(b)-f(a));
```
## Slightly formatted:
```
f=s=>s.split`:`.reduce((a,e,i)=>a+e*(!i?60:1),0);
t=n=>~~(n/60)+":"+n%60;
t(f(b)-f(a));
```
I feel there could be some some savings in there.. but I am not seeing them at present.
Edit - excellent suggestions in the comments.
[Answer]
# PHP, ~~55~~ 53 bytes
```
<?=date('i:s',($s=strtotime)($argv[2])-$s($argv[1]));
```
takes input from command line arguments
[Answer]
# Rebol, 5 bytes
```
b - a
```
Assuming I didn't miss any rules..
Rebol has arithmetic built-in for a number of literal data types.
This also applies to its descendants such as [Red](http://www.red-lang.org)
[Answer]
## C#, 72 bytes
```
using System;a=>b=>((DateTime.Parse(b)-DateTime.Parse(a))+"").Remove(5);
```
Takes input as strings.
`b="3:15"` `a="1:45"`.
### Explanation:
Because `DateTime.Parse()` returns a Date in `hh:mm:ss` format, I am able to parse the result into a string using `+""`, then trim the trailing `:00`.
This works with `hh:mm` because there are both 60 seconds in a minute and 60 minutes in an hour.
`0:01` `0:00` returns `0:01`
`1:00` `0:55` returns `0:05`
`3:15` `1:45` returns `1:30`
[Answer]
# Pyth, ~~47~~ ~~45~~ ~~44~~ 40 Bytes
```
J.U-Zbm+*60hdedmmvkcd\:.z%"%d:%02d".DJ60
```
Takes the input separated by newlines.
Pyth had no time built-ins useful for this. I tried some fancy eval() stuff but apparantly Pyth can't eval stuff with `*` or any leading zeroes whatsoever. This got much longer than i hoped. Quite some bytes are spent on adding a leading zero to the output. At least I'm shorter than bash. Will add explanation if asked.
[Try this!](https://pyth.herokuapp.com/?code=J.U-Zbm%2B%2a60hdedmmvkcd%5C%3A.z%25%22%25d%3A%2502d%22.DJ60&input=1%3A45%0A2%3A05&test_suite=1&test_suite_input=0%3A00%0A0%3A01%0A0%3A55%0A1%3A00%0A1%3A45%0A3%3A15&debug=0&input_size=2)
### alternative solution, 48 Bytes
```
J.U-Zbm+*60hdh_dmmvkcd\:.z
K%J60
s[/J60\:*<KT\0K
```
[Answer]
# Haskell, ~~98~~ ~~127~~ 86 Bytes
```
r(m:_:s)=60*read[m]+read s
a#b|(d,m)<-divMod(r b-r a)60=show d++':':['0'|m<=9]++show m
```
[Try it online!](https://tio.run/nexus/haskell#@1@kkWsVb1WsaWtmoFWUmpgSnRurDaIVirkSlZNqNFJ0cjVtdFMyy3zzUzSKFJJ0ixQSNc0MbIsz8ssVUrS11a3UraLVDdRrcm1sLWO1tcHiuf9zEzPzFGwVCkpLgkuKFFQUlAytTCyVlJWMrIzMlP4DAA "Haskell – TIO Nexus")
But I wonder if there are some library functions for this
EDIT: Removed import, also fixed an error where it showed m:s instead of m:ss
Also, well-formatted version:
```
convert :: String -> Integer
convert (a:_:b) = (read [a])*60+(read b)
diffTime :: String -> String -> String
diffTime s1 s2 = let (d,m) = divMod (c b-c a) 60 in show d ++ ":" ++ pad2d m
pad2d :: Int -> String
pad2d n = ['0'|n<=9]++show n
```
EDIT2: Golfed off (30?) bytes thanks to Laikoni! Also golfed some other misc. bytes.
[Answer]
# T-SQL, 238 bytes
```
CREATE PROCEDURE d @a time,@b time AS BEGIN DECLARE @d int DECLARE @s varchar(2) SET @d=datediff(s,@a,@b);SET @s=CAST(@d%3600/60 AS VARCHAR(3)) SELECT CAST(@d/3600 AS VARCHAR(3))+':'+(SELECT CASE WHEN LEN(@s)=1 THEN '0'+@s ELSE @s END)END
```
Usage:
```
EXEC d '00:55','01:00'
```
Seeing the PostGres example earlier I realised I hadn't seen many golfing attempts in SQL so I had a go at it in T-SQL. Now I know *why* you don't see much golfing in SQL :D
[Answer]
# [CJam](https://sourceforge.net/p/cjam), ~~34~~ ~~33~~ 25 bytes
*Saved 8 bytes thanks to Martin Ender!*
```
{r':/60b}2*\m60mds2Te[':\
```
[Try it online!](https://tio.run/nexus/cjam#@19dpG6lb2aQVGukFZNrZpCbUmwUkhqtbhXz/7@hlYmpgrGVoSkA "CJam – TIO Nexus")
**Explanation**
```
{             e# Start of block
 r            e#  Read one time from input
 ':/          e#  Split on colons, gives [minutes seconds]
 60b          e#  Convert from base 60
}2*           e# Run this block 2 times
              e# At this point, we have the two times in seconds on the stack
\             e# Swap top elements
m             e# Subtract
60md          e# Divmod the result by 60, to convert back to minutes and seconds
s             e# Convert the seconds to a string
2Te[          e# Pad it to 2 characters by adding 0s to the left (T = 0)
':            e# Push a colon character
\             e# Swap top elements, bringing seconds back to the top
```
[Answer]
## T-SQL, 82 Bytes
```
select left(cast(dateadd(minute, datediff(S,'0:00','0:01')/60,114) as time(0)), 5)
```
[Answer]
# Python, 160 bytes
I am still new to code golf so if anyone has any suggestions, I would appreciate it.
```
a, b = input()
def z(x):
    x = x.split(":")
    return int(x[0])*60+int(x[1])
a, b = z(a),z(b)
s, m = b-a,0
while s >= 60:
    s -= 60
    m += 1
print(str(m)+":"+str(s))
```
[Answer]
## REXX, 79 bytes
```
arg t q
say right(time(,f(q)-f(t),s),5)
f:return time(s,'00:'right(arg(1),5,0))
```
[Answer]
# Pyth, 28
```
%"%d:%02d".Dh.+misMcd\:60Q60
```
[Try it](https://pyth.herokuapp.com/?code=%25%22%25d%3A%2502d%22.Dh.%2BmisMcd%5C%3A60Q60&input=%5B%220%3A00%22%2C%20%220%3A01%22%5D%0A%5B%220%3A55%22%2C%20%221%3A00%22%5D%0A%5B%221%3A45%22%2C%20%223%3A15%22%5D&test_suite=1&test_suite_input=%5B%220%3A00%22%2C%20%220%3A01%22%5D%0A%5B%220%3A55%22%2C%20%221%3A00%22%5D%0A%5B%221%3A45%22%2C%20%223%3A15%22%5D&debug=0).
### Explanation
```
                   cd\:      # lambda to split c on ":"
                 sM          # map to convert string to int
               mi      60Q   # convert from base-60 list to give seconds
             .+              # delta of the two seconds values
            h                # single-item list to int
          .D              60 # divmod by 60
%"%d:%02d"                   # format output
```
[Answer]
# Java 7, 164 bytes
```
String c(String a,String b){long s=x(b,1)-x(a,1)+(x(b,0)-x(a,0))*60,m=s%60;return(s/60)+":"+(m>9?m:"0"+m);}long x(String s,int i){return new Long(s.split(":")[i]);}
```
**Explanation:**
```
String c(String a, String b){       // Method with two String parameters and String return-type
  long s = x(b,1) - x(a,1)          //  Get difference in seconds from input times
           + (x(b,0) - x(a,0)*60,   //   plus the difference in minutes times 60 to get the seconds
    m = s%60;                       //  Temp variable of seconds after we've subtracted the minutes (used multiple times)
  return (s/60)                     //  Return minutes
    +":"                            //   plus ":"
    +(m>9?m:"0"+m);                 //   plus seconds (with a leading 0 if necessary)
}                                   // End of method
long x(String s,int i){             // Separate ethod with String and Integer parameters and long return-type
  return new Long(s.split(":")[i];  //  Return either minutes or seconds of String parameter based on the index
}                                   // End of method
```
**Test code:**
[Try it here.](https://tio.run/nexus/java-openjdk#hY1Ba4QwEIXv@yuGQGGmujbSKlSx/QP1tMdlD9GVEkiimLi1iL/dRteedy5v3vC9N7US1kI5LSfXS/MNNe6LCPelokm1Xm0xYhXGdBxReAlwtfxuOdFzykNd2KeU533jht6gfUk5BSxjAeqP90@dMc4CTfm81Y3/j2wojQNJ0z0GpvmBL0@gjWynpEPfQGd58cEFoBsqJWuwTjgvt1ZeQQtp9rLzBQRNB/BTgoZiKyuR8u10@rWu0VE7uKjztFMGdVQj4xnnLIRVY0YP4SRZ4XgNPYLj7G2DX7M42eH5MC9/)
```
class M{
  String c(String a,String b){long s=x(b,1)-x(a,1)+(x(b,0)-x(a,0))*60,m=s%60;return(s/60)+":"+(m>9?m:"0"+m);}long x(String s,int i){return new Long(s.split(":")[i]);}
  public static void main(String[] a){
    M m = new M();
    System.out.println(m.c("0:00", "0:01"));
    System.out.println(m.c("0:55", "1:00"));
    System.out.println(m.c("1:45", "3:15"));
  }
}
```
**Output:**
```
0:01
0:05
1:30
```
[Answer]
# TXR Lisp, 101 bytes
```
$ txr -e '(awk (:let (s "%M:%S"))
               ((mf (time-parse s))
                (prn (time-string-local (- [f 1].(time-utc) [f 0].(time-utc)) s))))'
13:49 14:49 
01:00
0:13 1:47
01:34
5:01 5:59
00:58
6:00 6:00
00:00
6:00 5:00
59:00
```
Condensed: `(awk(:let(s"%M:%S"))((mf(time-parse s))(prn(time-string-local(-[f 1].(time-utc)[f 0].(time-utc))s))))`
[Answer]
# [Ruby](https://www.ruby-lang.org/), 91 bytes
```
require'time';t=Time;d=t.parse($*[1])-t.parse($*[0]);puts t.at(d.to_i).utc.strftime '%H:%M'
```
[Try it online!](https://tio.run/nexus/ruby#@1@UWliaWZSqXpKZm6puXWIbAqStU2xL9AoSi4pTNVS0og1jNXWRuAaxmtYFpSXFCiV6iSUaKXol@fGZmnqlJcl6xSVFaSBjFNRVPaxUfdX///9vaGVi@t/YytAUAA "Ruby – TIO Nexus")
Takes input from command line arguments.
### Invocation:
```
ruby outatime.rb $A $B
```
### Example:
```
ruby outatime.rb 1:45 3:15
```
Output:
> 
> 01:30
> 
> 
> 
[Answer]
## PowerShell 47 Bytes
```
param($s,[timespan]$f)($f-$s).ToString("h\:mm")
```
Simple timespan math and coverting to hour and seconds string.
[Answer]
# JavaScript, 88 bytes
```
a=>b=>{c=a.split`:`,d=b.split`:`;return +c[0]-d[0]-d[1]>c[1]?1:0+":"+(+c[1]+60-d[1])%60}
```
[Try it online!](https://tio.run/nexus/javascript-node#S7P9n2hrl2RrV51sm6hXXJCTWZJglaCTYpsE51gXpZaUFuUpaCdHG8TqpkAIw1i7ZCBhb2hloK1kpaStoQ3iapsZgOU0Vc0Mav8n5@cV5@ek6uXkp2ukaSgZWhkbKGlqKBlYGZsqaWr@BwA "JavaScript (Node.js) – TIO Nexus")
## Explanation:
Splits the inputs on the colon
```
c=a.split`:`,d=b.split`:`;
```
Converts string to int
```
+c[0]
```
Gets the minute value
```
+c[0]-d[0]-d[1]>c[1]?1:0
```
Gets the second value
```
(+c[1]+60-d[1])%60
```
Returns the string minutes:seconds
```
return +c[0]-d[0]-d[1]>c[1]?1:0+":"+(+c[1]+60-d[1])%60
```
]