SQL DATEFROMPARTS

SQL DATEFROMPARTS function 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 syntax, it accepts three arguments to build a date. This SQL Server method returns date data type value as output.

SQL DATEFROMPARTS Function Example

In this DateTime example, we will show you the use the Date from parts.

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