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. In this article we will show you, How to use the SQL Server SMALLDATETIMEFROMPARTS function with practical example.
SQL SMALLDATETIMEFROMPARTS Syntax
The basic syntax of the SMALLDATETIMEFROMPARTS Function in SQL Server is as follows:
SMALLDATETIMEFROMPARTS (year, month, day, hour, minute)
As you can see, this function accepts 5 arguments to built a small date and time. This function returns smalldatetime data type value as output.
SQL SMALLDATETIMEFROMPARTS Function Example 1
In this example, we will show you the use of SQL Server SmallDateTimefromParts 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, last statement is throwing an error. Let me show you the result
Thank You for Visiting Our Blog