SUBTIME
SUBTIME is a SQL function that subtracts a specified time from a given time value. It returns the result as a time or datetime value depending on the initial value provided.
SUBTIME(time, expr)
- time: This is a valid time or datetime expression from which the desired time interval will be subtracted. It could be a date, time, datetime or a string formatted as an SQL date, time, or datetime.
- expr: This parameter signifies the time interval that will be subtracted from the original time. This could either be represented in terms of a string that specifies time (like ‘02
Example
Output
Explanation
The SUBTIME()
function subtracts a time value from a date or datetime. In the above code, it subtracts ‘3:0:0’ (3 hours) from ‘2022-12-31 12:00:00’ to return a new datetime ‘2022-12-31 09:00:00’.