SQL TIMEFROMPARTS

SQL TIMEFROMPARTS function is one of the Date and Time Function, which will return a time value from the users specified time, and precision parts. The basic syntax of the TIMEFROMPARTS Function in SQL Server is as follows:

TIMEFROMPARTS (day, hour, minute, seconds, fractions, precisions)

As you can see from the above syntax, this time from parts function accepts six arguments to build time with precision. This SQL Server TIMEFROMPARTS function returns time data type as output. Here, the Fraction value will always depend upon the Precision. If the precision value is 2, then the value of the fraction must also be 2 (or less than 2); otherwise, SQL Server will throw an error.

SQL TIMEFROMPARTS Function Example

In this Date and Time Function example, we will show you the use of SQL Server Time From Parts function

-- Example for SQL TIMEFROMPARTS Function
SELECT TIMEFROMPARTS ( 10, 09, 18, 5, 1 ) AS Result

SELECT TIMEFROMPARTS ( 10, 09, 18, 50, 2 ) AS Result

SELECT TIMEFROMPARTS ( 10, 09, 18, 503, 3 ) AS Result

-- Let me try the NULL values
SELECT TIMEFROMPARTS ( NULL, 09, 18, 504, 3 ) AS Result

-- Precision Value is greater than Fraction
SELECT TIMEFROMPARTS ( 10, 09, 18, 503, 7 ) AS Result

-- Precision Value is Les than Fraction. Invalid argument
SELECT TIMEFROMPARTS ( 10, 09, 18, 503, 2 ) AS Result
SQL TIMEFROMPARTS 1

As you can see, the last statement is throwing an error. This is because, Fraction value = 503, and Precision = 2 (does not match). Let me show you the result

SQL TIMEFROMPARTS 2