// dates & times reference

SQL SUBTIME function

Subtracts a time span from a datetime or another time, the mirror of ADDTIME.

Categoría
Dates & times
Returns
datetime / time
In this category
74 of 121

Sintaxis

SUBTIME(dt, time_value)

Soporte del motor

MotorSupportNotas
SQL Server Different name or syntax DATEADD with negative parts
PostgreSQL Different name or syntax dt - INTERVAL '2 hours 30 minutes'
MySQL Sí Supported under this name.
SQLite Different name or syntax datetime(d, '-2 hours')
Oracle Different name or syntax dt - INTERVAL '2:30' HOUR TO MINUTE

Ejemplos

MySQL

SELECT SUBTIME('2026-08-01 01:00:00', '02:30:00');  -- 2026-07-31 22:30:00

PostgreSQL

SELECT '2026-08-01 01:00:00'::timestamp - INTERVAL '2:30';

Conviene saberlo

  • Like ADDTIME, the span is a TIME value ('02:30:00', or '1 02:30:00' with a day part); months and years need DATE_SUB with an INTERVAL.
  • SUBTIME('2026-08-01 01:00:00', '02:30:00') correctly rolls back to 2026-07-31 22:30:00 when the first argument is a datetime.
  • There is no DATE_SUB-style bare-day shortcut here; use DATE_SUB for day granularity.

Questions about SUBTIME

SUBTIME vs DATE_SUB?

SUBTIME takes a TIME span like '02:30:00'; DATE_SUB takes INTERVAL unit terms and bare day counts. Use SUBTIME for sub-day precision on the clock.

What is the Oracle equivalent?

d - INTERVAL '0 02:30:00' DAY TO SECOND, or plain subtraction with a fraction of a day: d - 2.5/24.

Browse every function in the SQL function reference, or see what the SQLly desktop app does for your database.

Cheat sheets for the engines that have it: SQL Server, PostgreSQL, MySQL, SQLite, Oracle.

// fewer lookups

Functions your engine actually has

SQLly's completion lists the built-in functions of the engine you're connected to, whether that's SQL Server, PostgreSQL, MySQL, SQLite or Oracle. Hover a function for help, and signature hints show each argument as you type.