MySQL numeric functions
MySQL string functions
MySQL Date/Time functions
MySQL aggregate functions
MySQL flow control functions
The SUBTIME()
function in MySQL is used to subtract a time value from a given time. The function takes two arguments: the original time and the time to be subtracted.
The basic syntax of the SUBTIME()
function is:
SUBTIME(time1, time2)
Where:
time1
is the original time.time2
is the time value to be subtracted from the original time.It's important to note that the function returns NULL if the arguments are invalid. Also, if the result goes below 0, MySQL will correctly show the negative time value.
Here's an example of how you might use it:
SELECT SUBTIME('18:30:00', '02:25:00') AS NewTime;
In this example, the function will subtract '02:25:00' from '18:30:00'. As a result, the NewTime
value would be '16:05:00'.
You can also use SUBTIME()
with datetime values. For example:
SELECT SUBTIME('2023-05-12 18:30:00', '1:1:1') AS NewDateTime;
In this case, the function subtracts 1 hour, 1 minute, and 1 second from the datetime '2023-05-12 18:30:00'. So, the NewDateTime
value would be '2023-05-12 17:28:59'.
Also, it's important to note that SUBTIME()
can handle time values over 24 hours. For example:
SELECT SUBTIME('30:00:00', '02:00:00') AS NewTime;
Here, '30:00:00' represents 30 hours. After subtracting '02:00:00' (2 hours), the result would be '28:00:00' (28 hours).
Time subtraction with MySQL SUBTIME:
SUBTIME
function.Using SUBTIME function in MySQL for time operations:
SUBTIME
function in MySQL to subtract a specified time interval from a given time.SELECT SUBTIME('12:30:00', '0:15:00') AS subtracted_time;
MySQL SUBTIME function example:
SUBTIME
function in MySQL to subtract time.SELECT SUBTIME('12:30:00', '0:15:00') AS subtracted_time;
How to subtract time in MySQL:
SUBTIME
function with the time value and the desired time interval to subtract.SELECT SUBTIME('12:30:00', '0:15:00') AS subtracted_time;
Time manipulation in MySQL: SUBTIME usage:
SUBTIME
function for time manipulation in MySQL to perform time subtraction.SELECT SUBTIME('12:30:00', '0:15:00') AS subtracted_time;
MySQL time subtraction with SUBTIME:
SUBTIME
function.SELECT SUBTIME('12:30:00', '0:15:00') AS subtracted_time;
Performing time calculations in MySQL using SUBTIME:
SUBTIME
function to subtract a specified time interval.SELECT SUBTIME('12:30:00', '0:15:00') AS subtracted_time;
Time arithmetic with SUBTIME in MySQL:
SUBTIME
function for subtracting time intervals.SELECT SUBTIME('12:30:00', '0:15:00') AS subtracted_time;