SUBTIME(DateTime1 or Time_Expression1, Time_Expression2);
The SUBTIME function Subtracts the Time_Expression2 value from the DateTime1 or Time_Expression1.
MySQL SUBTIME function Example
The following are the list examples that help you understand the use of this MySQL SUB TIME function.
In this example, First, we are subtracting 2 Hours, 10 Minutes, and 12 Seconds from the time expression 10:11:22. Next, we are subtracting the time along with Microseconds.
SELECT SUBTIME('10:11:22', '2:10:12');
SELECT SUBTIME('10:11:22', '04:09:12.111222');
SELECT SUBTIME('10:11:22.999888', '04:09:12.111222');
In this MySQL Sub Time function example, we subtracted 10 Hours, 09 Minutes, 12 Seconds, and 111222 Microseconds. Next, we subtracted 100 Hours and 1000 Hours. The impact of subtracting these many hours (100 and 1000) changes the value of the date too.
SELECT SUBTIME('2019-02-28 23:59:59.999888', '10:09:12.111222');
SELECT SUBTIME('2019-02-28 23:59:59.999888', '100:09:12.111222');
SELECT SUBTIME('2019-02-28 23:59:59', '1000:09:12');