SQL DATEFROMPARTS

SQL DATEFROMPARTS function is one of the Date and Time Function, which will return a date value from the users specified parts. The basic syntax of the DATEFROMPARTS Function is as follows:

DATEFROMPARTS (year, month, day)

As you can see from the DATEFROMPARTS syntax, this function accepts three arguments to build a date. This SQL Server function returns date data type value as output.

SQL DATEFROMPARTS Function Example

In this Date and Time Function example, we will show you the use the 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
SQL DATEFROMPARTS 1

As you can see, the last statement is throwing an error. It is because there is no 29th date in February month. Let me show you the result

SQL DATEFROMPARTS 2