// dates & times reference

SQL TIMEFROMPARTS function

Returns a time from integers. SQL Server's TIMEFROMPARTS takes five arguments with fractional precision; MySQL's MAKETIME takes three.

Categoría
Dates & times
Returns
time
In this category
24 of 121

Sintaxis

TIMEFROMPARTS(hh, mm, ss, fff, precision)  -- SQL Server
MAKE_TIME(hh, mm, ss)  -- PostgreSQL
MAKETIME(hh, mm, ss)  -- MySQL

Each block is a separate form. The support table and the examples show which engine takes which.

Soporte del motor

MotorSupportNotas
SQL Server Sí Supported under this name.
PostgreSQL Different name or syntax make_time(hh, mm, ss)
MySQL Different name or syntax MAKETIME(hh, mm, ss)
SQLite Different name or syntax printf into a 'HH:MM:SS' string
Oracle Not built in no direct function; TO_DSINTERVAL builds an interval, not a time

Ejemplos

SQL Server

SELECT TIMEFROMPARTS(9, 30, 0, 0, 0) AS start_time;

MySQL

SELECT MAKETIME(9, 30, 0) AS start_time;

PostgreSQL

SELECT make_time(9, 30, 0) AS start_time;

Conviene saberlo

  • SQL Server's last two arguments work together: the fraction must fit the declared precision (500 with precision 3 is .500), and precision 0 requires a fraction of 0.
  • MySQL's MAKETIME accepts hours up to 838 because TIME doubles as a duration type, so MAKETIME(30, 0, 0) is legal there and an error on SQL Server and PostgreSQL.
  • SQLite and Oracle have no constructor; SQLite builds the string by hand and Oracle, which has no TIME type, composes a DATE or an INTERVAL instead.

Questions about TIMEFROMPARTS

Why does TIMEFROMPARTS have five arguments?

Arguments four and five are the fractional-seconds value and its precision: TIMEFROMPARTS(9,30,0,500,3) means 09:30:00.500.

What is the hour limit for a time?

Clock times stop at 23. MySQL's TIME type allows up to 838 hours because it doubles as a duration type: MAKETIME(100,0,0) is legal there.

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.

// 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.