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.
In this article we will show you, How to use the SQL Server TIMEFROMPARTS function with practical example.
SQL TIMEFROMPARTS Syntax
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 function accepts 6 arguments to built a time with precision.
This function returns time data type as output. Here, Fraction value will always depends upon the Precision. If the precision value is 2 then the value of the fraction must also be 2 (or less than 2) otherwise, it will throw an error.
SQL TIMEFROMPARTS Function Example
In this 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
As you can see from the above screenshot, last statement is throwing an error. This is because, Fraction value = 503, and Precision = 2 (does not match). Let me show you the result
Thank You for Visiting Our Blog