SQL SMALL DATETIME FROM PARTS

SQL SMALL DATETIME FROMPARTS function is one of the Date and Time Function, which will return a small date and time value from the users specified parts. The basic syntax of the SMALL DATETIME FROM PARTS Function is as follows:

SMALLDATETIMEFROMPARTS (year, month, day, hour, minute)

As you can see, this SMALLDATETIMEFROMPARTS function accepts five arguments to build a small date and time. This SQL Server function returns smalldatetime data type value as output.

SQL SMALL DATETIME FROM PARTS Function Example

In this example, we will show you the use of SQL Server Small DateTime from Parts function. It will also explain what will happen if you pass NULL values or invalid arguments to this function.

-- Example for SQL SMALLDATETIMEFROMPARTS Function
SELECT SMALLDATETIMEFROMPARTS ( 2017, 11, 19, 11, 35 ) AS Result

SELECT SMALLDATETIMEFROMPARTS ( 2017, 11, 19, 00, 35 ) AS Result

SELECT SMALLDATETIMEFROMPARTS ( 2017, 11, 19, 00, 00 ) AS Result

-- Let me try the NULL values
SELECT SMALLDATETIMEFROMPARTS ( NULL, 11, 19, 11, 35 ) AS Result

-- Feb 2016 is a Leap year
SELECT SMALLDATETIMEFROMPARTS ( 2016, 02, 29, 19, 11) AS Result

-- Feb 2014 is not a leap year. So, Invalid Argument 29
SELECT SMALLDATETIMEFROMPARTS ( 2014, 02, 29, 19, 11) AS Result
SQL SMALLDATETIMEFROMPARTS 1

The last statement is throwing an error. Let me show you the Date and Time Function result

SQL SMALLDATETIMEFROMPARTS 2