SQL DATEFROMPARTS function is one of the Date and Time Function, which will return a date value from the users specified parts.
In this article we will show you, How to use the SQL Date from Parts function with practical example.
SQL DATEFROMPARTS Syntax
The basic syntax of the DATEFROMPARTS Function in SQL Server is as follows:
DATEFROMPARTS (year, month, day)
As you can see from the above syntax, this function accepts 3 arguments to built a date. This function returns date data type value as output.
SQL DATEFROMPARTS Function Example 1
In this example, we will show you the use of SQL Server Datefromparts function
-- Example for SQL DATEFROMPARTS Function SELECT DATEFROMPARTS ( 2017, 12, 19) AS Result SELECT DATEFROMPARTS ( 2014, 02, 25) AS Result -- Let me try with Null Values SELECT DATEFROMPARTS ( NULL, 12, 19 ) AS Result SELECT DATEFROMPARTS ( 2017, 12, NULL ) AS Result -- Feb 2016 is a Leap year SELECT DATEFROMPARTS ( 2016, 02, 29) AS Result -- Feb 2014 is not a leap year. So, Invalid Argument 29 SELECT DATEFROMPARTS ( 2014, 02, 29) AS Result
As you can see from the above screenshot, last statement is throwing an error. This is because, there is no 29th date in February month. Let me show you the result
Thank You for Visiting Our Blog