SQL DATETIMEOFFESTFROMPARTS function is one of the Date and Time Function, used to return a date time offset value from the users specified date and time parts along with fractions, and precision. In this article we will show you, How to use the SQL Server DATETIMEOFFESTFROMPARTS function with practical example.
SQL DATETIMEOFFESTFROMPARTS Syntax
The basic syntax of the DATETIMEOFFESTFROMPARTS Function in SQL Server is as follows:
1 2 |
DATETIMEOFFESTFROMPARTS (year, month, day, hour, minute, seconds, fractions, hours_offset, minutes_offset, precision) |
This function returns datetimeoffset data type value as output. Here, Fraction value will always depends upon the Precision. If the precision value is 5 then the value of the fraction must also be 5 (or less than 5) otherwise, it will throw an error.
SQL DATETIMEOFFESTFROMPARTS Function Example 1
In this example, we will show you the use of SQL Server DateTimeOffsetFromParts function
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
-- Example for SQL DATETIMEOFFSETFROMPARTS Function SELECT DATETIMEOFFSETFROMPARTS ( 2017, 11, 19, 16, 25, 09, 3, 12, 30, 1 ) AS Result SELECT DATETIMEOFFSETFROMPARTS ( 2017, 11, 19, 16, 25, 09, 36, 12, 30, 2 ) AS Result SELECT DATETIMEOFFSETFROMPARTS ( 2017, 11, 19, 16, 25, 09, 363, 12, 30, 3 ) AS Result -- Let me try the NULL values SELECT DATETIMEOFFSETFROMPARTS ( 2017, 11, 19, 16, NULL, 09, 363, 12, 30, 3 ) AS Result -- Precision Value is greater than Fraction SELECT DATETIMEOFFSETFROMPARTS ( 2017, 11, 19, 16, 25, 09, 363, 12, 30, 7 ) AS Result -- Precision Value is Les than Fraction. Invalid argument SELECT DATETIMEOFFSETFROMPARTS ( 2017, 11, 19, 16, 25, 09, 363, 12, 30, 2 ) AS Result |
As you can see, last statement is throwing an error. This is because, Fraction value = 363, and Precision = 2 (does not match).
Let me show you the result
Thank You for Visiting Our Blog
Share your Feedback, or Code!!