SQL Server DATETIMEFROMPARTS function is one of the Date and Time Functions, which will return a DateTime value from the user’s specified parts. The basic syntax of the SQL DATETIMEFROMPARTS Function is as follows:
DATETIMEFROMPARTS (year, month, day, hour, minute, seconds, milliseconds)
As you can see from the above syntax, it accepts seven arguments to build a date and time. This method returns the DateTime data type value as output. Please refer to the list of SQL Date and time functions available on our SQL Server Tutorial page.
SQL DATETIMEFROMPARTS Example
In this Date and Time example, we will show you the use of SQL Server Date time from parts function.
TIP: Please refer to the SQL DATETIMEOFFSETFROMPARTS and SQL SMALLDATETIMEFROMPARTS articles.
SELECT DATETIMEFROMPARTS ( 2017, 12, 19, 10, 09, 18, 503 ) AS Result SELECT DATETIMEFROMPARTS ( 2017, 12, 19, 10, 09, 18, 0 ) AS Result SELECT DATETIMEFROMPARTS ( 2017, 12, 19, 00, 00, 18, 503 ) AS Result -- Let me try the NULL values SELECT DATETIMEFROMPARTS ( NULL, 12, 19, 00, 00, 18, 503 ) AS Result SELECT DATETIMEFROMPARTS ( 2017, 12, 19, NULL, 00, 18, 503 ) AS Result
