TIMEFROMPARTS Function was introduced with SQL Server 2012. This function is used to get Time value from Hour, Minute, Second, Fraction and Precision values.
Syntax:
TIMEFROMPARTS (Hour, Minute, Second, Fraction, Precision)
Example:
Declare @Hour int = 11 Declare @Minute int = 50 Declare @Second int = 40 Declare @Fraction int = 5 Select TIMEFROMPARTS(@Hour,@Minute,@Second,@Fraction,1) Select TIMEFROMPARTS(@Hour,@Minute,@Second,@Fraction,2) Select TIMEFROMPARTS(@Hour,@Minute,@Second,@Fraction,3)
Result:
11:50:40.5
11:50:40.05
11:50:40.005
Note:
- When fractions has a value of 5 and precision has a value of 1, then the value of fractions represents 5/10 of a second.
- When fractions has a value of 5 and precision has a value of 2, then the value of fractions represents 5/100 of a second.
- When fractions has a value of 5 and precision has a value of 3, then the value of fractions represents 5/1000 of a second.