SQL SMALLDATETIMEFROMPARTS 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 SMALLDATETIMEFROMPARTS Function in SQL Server is as follows:
SMALLDATETIMEFROMPARTS (year, month, day, hour, minute)
SQL SMALLDATETIMEFROMPARTS 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
As you can see from the above screenshot, the last statement is throwing an error. Let me show you the Date and Time Function result