diff --git a/to find difference between current time and given time b/to find difference between current time and given time new file mode 100644 index 0000000..60daea9 --- /dev/null +++ b/to find difference between current time and given time @@ -0,0 +1,42 @@ +# Python program to find the +# difference between two times + + +# function to obtain the time +# in minutes form +def difference(h1, m1, h2, m2): + + # convert h1 : m1 into + # minutes + t1 = h1 * 60 + m1 + + # convert h2 : m2 into + # minutes + t2 = h2 * 60 + m2 + + if (t1 == t2): + print("Both are same times") + return + else: + + # calculating the difference + diff = t2-t1 + + # calculating hours from + # difference + h = (int(diff / 60)) % 24 + + # calculating minutes from + # difference + m = diff % 60 + + print(h, ":", m) + +# Driver's code +if __name__ == "__main__": + + difference(7, 20, 9, 45) + difference(15, 23, 18, 54) + difference(16, 20, 16, 20) + +# This code is contributed by SrujayReddy