Tutorial Gateway

  • C Programming
  • Java
  • R
  • SQL
  • MySQL
  • Python
  • BI Tools
    • Informatica
    • Tableau
    • Power BI
    • SSIS
    • SSRS
    • SSAS
    • MDX
    • QlikView
  • About
    • About Us
    • Contact Us

SQL DATETIMEOFFESTFROMPARTS

19-12-2017 by suresh Leave a Comment

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

SQL DATETIMEOFFSETFROMPARTS 1

Let me show you the result

SQL DATETIMEOFFSETFROMPARTS 2

Thank You for Visiting Our Blog

Placed Under: SQL

Share your Feedback, or Code!! Cancel reply

Trending

  • SQL Server Integration Services (SSIS)
  • SQL Server Tutorial
  • SQL Server Reporting Services (SSRS)
  • Home
  • C Program to Calculate the Sum and Average of n Number
  • Tableau
  • C Program to Print Prime Numbers from 1 to 100

Stay in Touch!

Sign Up to receive Email updates on Latest Tutorials

  • Blogger
  • C Programs
  • Java Programs
  • SQL
  • SSIS
  • SSRS
  • Tableau
  • JavaScript

Copyright © 2018 | Tutorial Gateway· All Rights Reserved by Suresh

Home | About Us | Contact Us | Privacy Policy