MySQL SUBTIME function is one of the Date Function, used to subtract time from existing DateTime or Time expression.
In this article, we will show you, How to use this MySQL SubTime function to subtract specified time from a given DateTime or Time expression with an example.
MySQL SUBTIME Syntax
The basic syntax of the SUBTIME() Function in MySQL is as shown below:
SUBTIME(DateTime1 or Time_Expression1, Time_Expression2);
This function Subtracts the Time_Expression2 value from the DateTime1 or Time_Expression1.
MySQL SUBTIME function Example
The following are the list examples which helps 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) will change the dates value 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');
Thank You for Visiting Our Blog