MySQL SUBTIME function is one of the Date Functions, used to subtract time from existing DateTime or Time expression. The syntax of the SUBTIME Function in MySQL is as shown below:
SUBTIME(DateTime1 or Time_Expression1, Time_Expression2);
From the above syntax, it 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 method.
In this Date method 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 method example, we subtracted 10 Hours, 09 Minutes, 12 Seconds, and 111222 Microseconds. Next, we subtracted 100 Hours and 1000 Hours. The impact of deducting 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');